Example #1
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));
 }
Example #2
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));
        }
Example #3
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));
        }
Example #4
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);
        }