예제 #1
0
        public async Task SignalReturns()
        {
            MutexThread waiter = MutexThread.Begin(CancellationToken.None);
            Mutex       m      = new Mutex();

            try
            {
                await waiter.WaitAsync(m);

                Task <WaitResult> childTask = Task.Run(() => Wait(m, 2));
                waiter.Release(m);
                var result = await childTask;
                Assert.True(result.Waited, "Other thread should have waited");
                Assert.InRange(result.TimeTaken.TotalSeconds, 0, 1);
            }
            finally
            {
                waiter.Release(m);
            }
        }
예제 #2
0
        public async Task SignalReturnsOnTime()
        {
            MutexThread waiter = MutexThread.Begin(CancellationToken.None);
            var         m      = new Mutex();

            try
            {
                await waiter.WaitAsync(m);

                Task <WaitResult> childTask = Task.Run(() => Wait(m, 10));
                await Task.Delay(MultTime(_step, 4));

                waiter.Release(m);
                WaitResult result = await childTask;
                Assert.True(result.Waited, "Other thread should have waited");
                Assert.InRange(result.TimeTaken, _step, MultTime(_step, 10));
            }
            finally
            {
                waiter.Release(m);
            }
        }
예제 #3
0
        public async Task SignalReturnsOnTime()
        {
            Task        complete;
            MutexThread waiter = MutexThread.Begin(CancellationToken.None, out complete);
            Mutex       m      = new Mutex();

            try
            {
                await waiter.WaitAsync(m);

                Task <WaitResult> childTask = Task.Run(() => Wait(m, 5));
                await Task.Delay(TimeSpan.FromSeconds(2));

                waiter.Release(m);
                var result = await childTask;
                Assert.True(result.Waited, "Other thread should have waited");
                Assert.InRange(result.TimeTaken.TotalSeconds, 1, 5);
            }
            finally
            {
                waiter.Release(m);
            }
        }
예제 #4
0
        public async Task NoPrematureReturn()
        {
            MutexThread waiter = MutexThread.Begin(CancellationToken.None);
            Mutex       m      = new Mutex();

            try
            {
                await waiter.WaitAsync(m);

                var result = await Task.Run(() => Wait(m, 2));

                Assert.False(result.Waited, "Other thread did not wait");
                Assert.InRange(result.TimeTaken.TotalSeconds, 1, 10000);
            }
            finally
            {
                waiter.Release(m);
            }
        }