Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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);
        }