private async Task B1() { this.b = this.x + 1; SchedulingPoint.Interleave(); this.x = this.b; await Task.CompletedTask; }
public void TestYield() { this.TestWithError(async r => { int x = 0; int a = 0; int b = 0; var t1 = Task.Run(async() => { a = x + 1; SchedulingPoint.Yield(); x = a; await Task.CompletedTask; }); var t2 = Task.Run(async() => { b = x + 1; SchedulingPoint.Yield(); x = b; await Task.CompletedTask; }); await Task.WhenAll(t1, t2); Specification.Assert(a > 1 || b > 1, string.Format("A: {0}, B: {1}", a, b)); }, configuration: this.GetConfiguration().WithTestingIterations(200), expectedError: "A: 1, B: 1", replay: true); }
private async Task B2() { this.b = this.x + 1; SchedulingPoint.Deprioritize(); this.x = this.b; await Task.CompletedTask; }
public Task CreateOrUpdateBlobAsync(string containerName, string blobName, byte[] blobContents) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(containerName); this.Containers[containerName][blobName] = blobContents; return(Task.CompletedTask); }
public Task CreateContainerIfNotExistsAsync(string containerName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(containerName); this.Containers.TryAdd(containerName, new Dictionary <string, byte[]>()); return(Task.CompletedTask); }
public Task <bool> ExistsBlobAsync(string containerName, string blobName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a read operation we invoke the 'Read' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Read(containerName); bool result = this.Containers.TryGetValue(containerName, out Dictionary <string, byte[]> container); return(Task.FromResult(result && container.ContainsKey(blobName))); }
public Task <byte[]> GetBlobAsync(string containerName, string blobName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a read operation we invoke the 'Read' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Read(containerName); var result = this.Containers[containerName][blobName]; return(Task.FromResult(result)); }
public Task <bool> DeleteContainerIfExistsAsync(string containerName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(containerName); bool result = this.Containers.Remove(containerName); return(Task.FromResult(result)); }
public void TestSuppressNoResumeTaskInterleaving() { this.Test(async r => { // Make sure the scheduler does not deadlock. SchedulingPoint.Suppress(); // Only interleavings of enabled operations should be suppressed. await Task.Run(() => { }); }, configuration: this.GetConfiguration().WithTestingIterations(100)); }
public Task <ICosmosContainer> CreateContainerAsync(string containerName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(containerName); this.State.CreateContainer(containerName); ICosmosContainer container = new MockCosmosContainer(containerName, this.State); return(Task.FromResult(container)); }
public Task DeleteAllBlobsAsync(string containerName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(containerName); if (this.Containers.TryGetValue(containerName, out Dictionary <string, byte[]> container)) { container.Clear(); } return(Task.CompletedTask); }
public Task DeleteItem(string partitionKey, string id) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(this.ContainerName); if (this.EmitRandomizedFaults && this.Generator.NextBoolean()) { throw new SimulatedDatabaseFaultException(); } this.State.DeleteItem(this.ContainerName, partitionKey, id); return(Task.CompletedTask); }
public Task <bool> DeleteBlobIfExistsAsync(string containerName, string blobName) { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(containerName); if (!this.Containers.TryGetValue(containerName, out Dictionary <string, byte[]> container)) { return(Task.FromResult(false)); } bool result = container.Remove(blobName); return(Task.FromResult(result)); }
public Task <T> UpsertItem <T>(T item) where T : DbItem { // We invoke this Coyote API to explicitly insert a "scheduling point" during the test execution // where the Coyote scheduler should explore a potential interleaving with another concurrently // executing operation. As this is a write operation we invoke the 'Write' scheduling point with // the corresponding container name, which can help Coyote optimize exploration. SchedulingPoint.Write(this.ContainerName); if (this.EmitRandomizedFaults && this.Generator.NextBoolean()) { throw new SimulatedDatabaseFaultException(); } var itemCopy = TestHelper.Clone(item); this.State.UpsertItem(this.ContainerName, itemCopy); return(Task.FromResult(itemCopy)); }
public void TestSuppressLockInterleaving() { this.Test(async r => { var set = new HashSet <int>(); var t1 = Task.Run(() => { SchedulingPoint.Suppress(); lock (set) { set.Remove(1); } lock (set) { set.Add(2); } SchedulingPoint.Resume(); }); var t2 = Task.Run(() => { SchedulingPoint.Suppress(); lock (set) { set.Remove(2); } lock (set) { set.Add(1); } SchedulingPoint.Resume(); }); await Task.WhenAll(t1, t2); Specification.Assert(set.Count is 1, $"Count is {set.Count}."); }, configuration: this.GetConfiguration().WithTestingIterations(100)); }
public void TestSuppressTaskInterleaving() { this.Test(async r => { int value = 0; SchedulingPoint.Suppress(); var t = Task.Run(() => { value = 2; }); SchedulingPoint.Resume(); value = 1; await t; Specification.Assert(value is 2, $"Value is {value}."); }, configuration: this.GetConfiguration().WithTestingIterations(100)); }
public void TestPollingTaskLivenessPropertyFailure() { this.TestWithError(async() => { var pollingTask = Task.Run(() => { while (true) { SchedulingPoint.Interleave(); } }); Specification.IsEventuallyCompletedSuccessfully(pollingTask); await pollingTask; }, configuration: this.GetConfiguration().WithMaxSchedulingSteps(10), errorChecker: (e) => { Assert.StartsWith("Found potential liveness bug at the end of program execution.", e); }, replay: true); }
public void TestSuppressAndResumeTaskInterleaving() { this.TestWithError(async r => { int value = 0; SchedulingPoint.Suppress(); SchedulingPoint.Resume(); var t = Task.Run(() => { value = 2; }); value = 1; await t; Specification.Assert(value is 2, $"Value is {value}."); }, configuration: this.GetConfiguration().WithTestingIterations(100), expectedError: "Value is 1.", replay: true); }