Exemplo n.º 1
0
 private async Task B1()
 {
     this.b = this.x + 1;
     SchedulingPoint.Interleave();
     this.x = this.b;
     await Task.CompletedTask;
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 private async Task B2()
 {
     this.b = this.x + 1;
     SchedulingPoint.Deprioritize();
     this.x = this.b;
     await Task.CompletedTask;
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        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)));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
 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));
 }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }