public void IncompleteDeferral_PreventsCompletion() { AsyncContext.Run(async() => { var dm = new DeferralManager(); var deferral = dm.GetDeferral(); await AssertEx.NeverCompletesAsync(dm.SignalAndWaitAsync()); }); }
public void FromEvent1_EventNeverRaised_NeverCompletes() { AsyncContext.Run(async() => { var timer = new System.Timers.Timer(); var task = AsyncFactory <ElapsedEventArgs> .FromEvent(timer, "Elapsed"); await AssertEx.NeverCompletesAsync(task); }); }
public void ReadLocked_PreventsWriterLock() { AsyncContext.Run(async() => { var rwl = new AsyncReaderWriterLock(); await rwl.ReaderLockAsync(); var task = rwl.WriterLockAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void WaitAsync_Unset_IsNotCompleted() { AsyncContext.Run(async() => { var ce = new AsyncCountdownEvent(1); var task = ce.WaitAsync(); Assert.AreEqual(1, ce.CurrentCount); await AssertEx.NeverCompletesAsync(task); }); }
public void WaitAsync_Unset_IsNotCompleted() { AsyncContext.Run(async() => { var are = new AsyncAutoResetEvent(); var task = are.WaitAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void TryEnqueueAsync_Full_DoesNotComplete() { AsyncContext.Run(async() => { var queue = new AsyncProducerConsumerQueue <int>(new[] { 13 }, 1); var task = queue.TryEnqueueAsync(7); await AssertEx.NeverCompletesAsync(task); }); }
public void TryDequeueAsync_Empty_DoesNotComplete() { AsyncContext.Run(async() => { var queue = new AsyncProducerConsumerQueue <int>(); var task = queue.TryDequeueAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void SignalZero_DoesNothing() { AsyncContext.Run(async() => { var barrier = new AsyncBarrier(1); Assert.AreEqual(1, barrier.ParticipantsRemaining); var task = barrier.SignalAndWaitAsync(0); Assert.AreEqual(1, barrier.ParticipantsRemaining); await AssertEx.NeverCompletesAsync(task); }); }
public void FromEvent1_AsyncEventNeverRaised_NeverCompletes() { AsyncContext.Run(() => Task.Run(async() => { var bgw = new BackgroundWorker(); bgw.DoWork += (_, __) => { new Semaphore(0, 1).WaitOne(); }; var task = AsyncFactory <RunWorkerCompletedEventArgs> .FromEvent(bgw, "RunWorkerCompleted"); bgw.RunWorkerAsync(); await AssertEx.NeverCompletesAsync(task); })); }
public void UpgradeableReadLocked_PreventsWriterLock() { AsyncContext.Run(async() => { var rwl = new AsyncReaderWriterLock(); var key = await rwl.UpgradeableReaderLockAsync(); Assert.IsFalse(key.Upgraded); var task = rwl.WriterLockAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void WaitAsync_NoSlotsAvailable_IsNotCompleted() { AsyncContext.Run(async() => { var semaphore = new AsyncSemaphore(0); Assert.AreEqual(0, semaphore.CurrentCount); var task = semaphore.WaitAsync(); Assert.AreEqual(0, semaphore.CurrentCount); await AssertEx.NeverCompletesAsync(task); }); }
public void MultipleDeferralsWithOneIncomplete_PreventsCompletion() { AsyncContext.Run(async() => { var dm = new DeferralManager(); var deferral1 = dm.GetDeferral(); var deferral2 = dm.GetDeferral(); var task = dm.SignalAndWaitAsync(); deferral1.Dispose(); await AssertEx.NeverCompletesAsync(task); }); }
public void Dequeue_WithTwoItems_OnlyCompletesFirstItem() { AsyncContext.Run(async() => { var queue = new DefaultAsyncWaitQueue <object>() as IAsyncWaitQueue <object>; var task1 = queue.Enqueue(); var task2 = queue.Enqueue(); queue.Dequeue().Dispose(); Assert.IsTrue(task1.IsCompleted); await AssertEx.NeverCompletesAsync(task2); }); }
public void EnqueueToAnyAsync_Full_DoesNotComplete() { AsyncContext.Run(async() => { var queue1 = new AsyncProducerConsumerQueue <int>(new[] { 13 }, 1); var queue2 = new AsyncProducerConsumerQueue <int>(new[] { 13 }, 1); var queues = new[] { queue1, queue2 }; var task = queues.EnqueueToAnyAsync(7); await AssertEx.NeverCompletesAsync(task); }); }
public void TryDequeueFromAnyAsync_Empty_DoesNotComplete() { AsyncContext.Run(async() => { var queue1 = new AsyncProducerConsumerQueue <int>(); var queue2 = new AsyncProducerConsumerQueue <int>(); var queues = new[] { queue1, queue2 }; var task = queues.TryDequeueFromAnyAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void WaitAsync_AfterReset_IsNotCompleted() { AsyncContext.Run(async() => { var mre = new AsyncManualResetEvent(); mre.Set(); mre.Reset(); var task = mre.WaitAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void MultipleWaitAsync_Set_OnlyOneIsCompleted() { AsyncContext.Run(async() => { var are = new AsyncAutoResetEvent(true); var task1 = are.WaitAsync(); var task2 = are.WaitAsync(); Assert.IsTrue(task1.IsCompleted); await AssertEx.NeverCompletesAsync(task2); }); }
public void WaitAsync_WithoutNotify_IsNotCompleted() { AsyncContext.Run(async() => { var mutex = new AsyncLock(); var cv = new AsyncConditionVariable(mutex); await mutex.LockAsync(); var task = cv.WaitAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void WaitAsync_SlotAvailable_IsCompleted() { AsyncContext.Run(async() => { var semaphore = new AsyncSemaphore(1); Assert.AreEqual(1, semaphore.CurrentCount); var task1 = semaphore.WaitAsync(); Assert.AreEqual(0, semaphore.CurrentCount); Assert.IsTrue(task1.IsCompleted); var task2 = semaphore.WaitAsync(); Assert.AreEqual(0, semaphore.CurrentCount); await AssertEx.NeverCompletesAsync(task2); }); }
public void EnqueueToAnyAsync_MultipleHaveRoom_OnlyEnqueuesOne() { AsyncContext.Run(async() => { var queue1 = new AsyncProducerConsumerQueue <int>(); var queue2 = new AsyncProducerConsumerQueue <int>(); var queues = new[] { queue1, queue2 }; var result = await queues.EnqueueToAnyAsync(13); Task task = ((result == queue1) ? queue2 : queue1).DequeueAsync(); await result.DequeueAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void LockReleased_WriteTakesPriorityOverRead() { AsyncContext.Run(async() => { var rwl = new AsyncReaderWriterLock(); Task writeLock, readLock; using (await rwl.WriterLockAsync()) { readLock = rwl.ReaderLockAsync(); writeLock = rwl.WriterLockAsync(); } await writeLock; await AssertEx.NeverCompletesAsync(readLock); }); }
public void ReaderLocked_ReaderReleased_ReaderAndWriterWaiting_DoesNotReleaseReaderOrWriter() { AsyncContext.Run(async() => { var rwl = new AsyncReaderWriterLock(); Task readLock, writeLock; await rwl.ReaderLockAsync(); using (await rwl.ReaderLockAsync()) { writeLock = rwl.WriterLockAsync(); readLock = rwl.ReaderLockAsync(); } await Task.WhenAll(AssertEx.NeverCompletesAsync(writeLock), AssertEx.NeverCompletesAsync(readLock)); }); }
public void ReaderLocked_ReaderReleased_ReaderAndUpgradingReaderWaiting_DoesNotReleaseReaderOrUpgradingReader() { AsyncContext.Run(async() => { var rwl = new AsyncReaderWriterLock(); Task readLock, upgradingReadLock; await rwl.ReaderLockAsync(); using (await rwl.ReaderLockAsync()) { var upgradeableReadLock = await rwl.UpgradeableReaderLockAsync(); upgradingReadLock = upgradeableReadLock.UpgradeAsync(); readLock = rwl.ReaderLockAsync(); } await Task.WhenAll(AssertEx.NeverCompletesAsync(upgradingReadLock), AssertEx.NeverCompletesAsync(readLock)); }); }
public void WaitAsync_AfterNotify_IsNotCompleted() { AsyncContext.Run(async() => { var mutex = new AsyncLock(); var cv = new AsyncConditionVariable(mutex); await Task.Run(async() => { using (await mutex.LockAsync()) { cv.Notify(); } }); await mutex.LockAsync(); var task = cv.WaitAsync(); await AssertEx.NeverCompletesAsync(task); }); }
public void MultipleWaits_Notify_OneIsCompleted() { AsyncContext.Run(async() => { var mutex = new AsyncLock(); var cv = new AsyncConditionVariable(mutex); var key = await mutex.LockAsync(); var task1 = cv.WaitAsync(); var __ = task1.ContinueWith(_ => key.Dispose()); await mutex.LockAsync(); var task2 = cv.WaitAsync(); await Task.Run(async() => { using (await mutex.LockAsync()) { cv.Notify(); } }); await task1; await AssertEx.NeverCompletesAsync(task2); }); }