Exemplo n.º 1
0
 public async Task NeverCompletesAsync_SynchronousTaskCompletes_Fails()
 {
     await Assert.ThrowsAsync <Exception>(async() =>
     {
         await AsyncAssert.NeverCompletesAsync(Task.FromResult(0));
     });
 }
        public async Task DequeueAsync_Empty_DoesNotComplete()
        {
            var queue = new AsyncProducerConsumerQueue <int>();

            var task = queue.DequeueAsync();

            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 3
0
        public async Task WaitAsync_Unset_IsNotCompleted()
        {
            var are = new AsyncAutoResetEvent();

            var task = are.WaitAsync();

            await AsyncAssert.NeverCompletesAsync(task);
        }
        public async Task ReadLocked_PreventsWriterLock()
        {
            var rwl = new AsyncReaderWriterLock();
            await rwl.ReaderLockAsync();

            var task = rwl.WriterLockAsync().AsTask();
            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 5
0
        public async Task OutputAvailableAsync_NoItemsInQueue_IsNotCompleted()
        {
            AsyncProducerConsumerQueue <int> queue = new AsyncProducerConsumerQueue <int>();

            Task <bool> task = queue.OutputAvailableAsync();

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 6
0
        public async Task DequeueAsync_Empty_DoesNotComplete()
        {
            AsyncProducerConsumerQueue <int> queue = new AsyncProducerConsumerQueue <int>();

            Task <int> task = queue.DequeueAsync();

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
        public async Task EnqueueAsync_Full_DoesNotComplete()
        {
            var queue = new AsyncProducerConsumerQueue <int>(new[] { 13 }, 1);

            var task = queue.EnqueueAsync(7);

            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 8
0
        public async Task WaitAsync_Unset_IsNotCompleted()
        {
            AsyncAutoResetEvent are = new AsyncAutoResetEvent();

            Task task = are.WaitAsync();

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 9
0
        public async Task Wait_Unset_IsNotCompleted()
        {
            var mre = new AsyncManualResetEvent();

            var task = Task.Run(() => mre.Wait());

            await AsyncAssert.NeverCompletesAsync(task);
        }
        public async Task ReadLocked_PreventsWriterLock()
        {
            AsyncReaderWriterLock rwl = new AsyncReaderWriterLock();
            await rwl.ReaderLockAsync();

            Task <IDisposable> task = rwl.WriterLockAsync().AsTask();
            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 11
0
        public async Task Wait_Unset_IsNotCompleted()
        {
            AsyncManualResetEvent mre = new AsyncManualResetEvent();

            Task task = Task.Run(() => mre.Wait());

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 12
0
        public async Task EnqueueAsync_Full_DoesNotComplete()
        {
            AsyncProducerConsumerQueue <int> queue = new AsyncProducerConsumerQueue <int>(new[] { 13 }, 1);

            Task task = queue.EnqueueAsync(7);

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
        public async Task OutputAvailableAsync_NoItemsInQueue_IsNotCompleted()
        {
            var queue = new AsyncProducerConsumerQueue <int>();

            var task = queue.OutputAvailableAsync();

            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 14
0
        public async Task CompletedDeferralFollowedByIncompleteDeferral_PreventsCompletion()
        {
            DeferralManager dm = new DeferralManager();

            dm.DeferralSource.GetDeferral().Dispose();
            IDisposable deferral = dm.DeferralSource.GetDeferral();
            Task        task     = dm.WaitForDeferralsAsync();
            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 15
0
        public async Task CompletedDeferralFollowedByIncompleteDeferral_PreventsCompletion()
        {
            var dm = new DeferralManager();

            dm.DeferralSource.GetDeferral().Dispose();
            var deferral = dm.DeferralSource.GetDeferral();
            var task     = dm.WaitForDeferralsAsync();
            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 16
0
        public async Task WaitAsync_NoSlotsAvailable_IsNotCompleted()
        {
            AsyncSemaphore semaphore = new AsyncSemaphore(0);

            Assert.Equal(0, semaphore.CurrentCount);
            Task task = semaphore.WaitAsync();

            Assert.Equal(0, semaphore.CurrentCount);
            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 17
0
        public async Task Dequeue_WithTwoItems_OnlyCompletesFirstItem()
        {
            var queue = new DefaultAsyncWaitQueue <object>() as IAsyncWaitQueue <object>;
            var task1 = queue.Enqueue();
            var task2 = queue.Enqueue();

            queue.Dequeue();
            Assert.True(task1.IsCompleted);
            await AsyncAssert.NeverCompletesAsync(task2);
        }
Exemplo n.º 18
0
        public async Task MultipleWaitAsync_Set_OnlyOneIsCompleted()
        {
            AsyncAutoResetEvent are = new AsyncAutoResetEvent(true);

            Task task1 = are.WaitAsync();
            Task task2 = are.WaitAsync();

            Assert.True(task1.IsCompleted);
            await AsyncAssert.NeverCompletesAsync(task2).ConfigureAwait(false);
        }
Exemplo n.º 19
0
        public async Task MultipleWaitAsync_Set_OnlyOneIsCompleted()
        {
            var are = new AsyncAutoResetEvent(true);

            var task1 = are.WaitAsync();
            var task2 = are.WaitAsync();

            Assert.True(task1.IsCompleted);
            await AsyncAssert.NeverCompletesAsync(task2);
        }
Exemplo n.º 20
0
        public async Task MultipleDeferralsWithOneIncomplete_PreventsCompletion()
        {
            var dm        = new DeferralManager();
            var deferral1 = dm.DeferralSource.GetDeferral();
            var deferral2 = dm.DeferralSource.GetDeferral();
            var task      = dm.WaitForDeferralsAsync();

            deferral1.Dispose();
            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 21
0
        public async Task WaitAsync_AfterReset_IsNotCompleted()
        {
            AsyncManualResetEvent mre = new AsyncManualResetEvent();

            mre.Set();
            mre.Reset();
            Task task = mre.WaitAsync();

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 22
0
        public async Task Dequeue_WithTwoItems_OnlyCompletesFirstItem()
        {
            IAsyncWaitQueue <object> queue = new DefaultAsyncWaitQueue <object>() as IAsyncWaitQueue <object>;
            Task <object>            task1 = queue.Enqueue();
            Task <object>            task2 = queue.Enqueue();

            queue.Dequeue();
            Assert.True(task1.IsCompleted);
            await AsyncAssert.NeverCompletesAsync(task2).ConfigureAwait(false);
        }
Exemplo n.º 23
0
 public async Task NeverCompletesAsync_TaskFaults_Fails()
 {
     await Assert.ThrowsAsync <Exception>(async() =>
     {
         var tcs      = new TaskCompletionSource <object>();
         var testTask = AsyncAssert.NeverCompletesAsync(tcs.Task);
         tcs.SetException(new Exception());
         await testTask;
     });
 }
Exemplo n.º 24
0
        public async Task WaitAsync_AfterReset_IsNotCompleted()
        {
            var mre = new AsyncManualResetEvent();

            mre.Set();
            mre.Reset();
            var task = mre.WaitAsync();

            await AsyncAssert.NeverCompletesAsync(task);
        }
        public async Task WaitAsync_NoSlotsAvailable_IsNotCompleted()
        {
            var semaphore = new AsyncSemaphore(0);

            Assert.Equal(0, semaphore.CurrentCount);
            var task = semaphore.WaitAsync();

            Assert.Equal(0, semaphore.CurrentCount);
            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 26
0
        public async Task MultipleDeferralsWithOneIncomplete_PreventsCompletion()
        {
            DeferralManager dm        = new DeferralManager();
            IDisposable     deferral1 = dm.DeferralSource.GetDeferral();
            IDisposable     deferral2 = dm.DeferralSource.GetDeferral();
            Task            task      = dm.WaitForDeferralsAsync();

            deferral1.Dispose();
            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
Exemplo n.º 27
0
        public async Task ShouldWaitForFilledSectionInEmptyBuffer()
        {
            // Given
            var buffer = new BytesBuffer(PageSize);

            // When
            var task = buffer.GetFilledSegmentAsync(_token);

            // Then
            await AsyncAssert.NeverCompletesAsync(task);
        }
        public async Task WaitAsync_WithoutNotify_IsNotCompleted()
        {
            AsyncLock mutex           = new AsyncLock();
            AsyncConditionVariable cv = new AsyncConditionVariable(mutex);

            await mutex.LockAsync();

            Task task = cv.WaitAsync();

            await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false);
        }
        public async Task WaitAsync_WithoutNotify_IsNotCompleted()
        {
            var mutex = new AsyncLock();
            var cv    = new AsyncConditionVariable(mutex);

            await mutex.LockAsync();

            var task = cv.WaitAsync();

            await AsyncAssert.NeverCompletesAsync(task);
        }
Exemplo n.º 30
0
        public async Task WaitAsync_SlotAvailable_IsCompleted()
        {
            AsyncSemaphore semaphore = new AsyncSemaphore(1);

            Assert.Equal(1, semaphore.CurrentCount);
            Task task1 = semaphore.WaitAsync();

            Assert.Equal(0, semaphore.CurrentCount);
            Assert.True(task1.IsCompleted);
            Task task2 = semaphore.WaitAsync();

            Assert.Equal(0, semaphore.CurrentCount);
            await AsyncAssert.NeverCompletesAsync(task2).ConfigureAwait(false);
        }