public void WaitAsync_NotEmpty_WaitsForTurn() { using (var turnstile = new Turnstile()) { var t1 = turnstile.WaitAsync(); var t2 = turnstile.WaitAsync(); var t3 = turnstile.WaitAsync(); Assert.That(turnstile.HasWaiting); TaskAssert.DoesNotEnd(t1); TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); Assert.That(turnstile.Turn()); TaskAssert.Completed(t1); TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); Assert.That(turnstile.Turn()); TaskAssert.Completed(t2); TaskAssert.DoesNotEnd(t3); Assert.That(turnstile.Turn()); TaskAssert.Completed(t3); Assert.That(!turnstile.HasWaiting); Assert.That(!turnstile.Turn()); } }
public void WaitAsync_Exceeded_WaitsForTurn() { using (var quota = new Quota(1L)) { var t1 = quota.WaitAsync(); var t2 = quota.WaitAsync(); var t3 = quota.WaitAsync(); Assert.That(quota.Balance, Is.EqualTo(-2L)); using (TaskAssert.Completed(t1)) { TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); } Assert.That(quota.Balance, Is.EqualTo(-1L)); using (TaskAssert.Completed(t2)) { TaskAssert.DoesNotEnd(t3); } Assert.That(quota.Balance, Is.EqualTo(0L)); using (TaskAssert.Completed(t3)) { } Assert.That(quota.Balance, Is.EqualTo(1L)); } }
public void WaitAsync_NotEmpty_CanCedeTurn() { using (var cts = new CancellationTokenSource()) using (var queue = new Queue()) { var t1 = queue.WaitAsync(); var t2 = queue.WaitAsync(cts.Token); var t3 = queue.WaitAsync(); using (TaskAssert.Completed(t1)) { TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); cts.Cancel(); TaskAssert.Cancelled(t2); TaskAssert.DoesNotEnd(t3); } using (TaskAssert.Completed(t3)) { Assert.That(!queue.IsEmpty); } Assert.That(queue.IsEmpty); } }
public void WaitAsync_NotEmpty_WaitsForTurn() { using (var queue = new Queue()) { var t1 = queue.WaitAsync(); var t2 = queue.WaitAsync(); var t3 = queue.WaitAsync(); using (TaskAssert.Completed(t1)) { TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); } using (TaskAssert.Completed(t2)) { TaskAssert.DoesNotEnd(t3); } using (TaskAssert.Completed(t3)) { Assert.That(!queue.IsEmpty); } Assert.That(queue.IsEmpty); } }
public void WaitAsync_NotEmpty_CanCedeTurn() { using (var cts = new CancellationTokenSource()) using (var turnstile = new Turnstile()) { var t1 = turnstile.WaitAsync(); var t2 = turnstile.WaitAsync(cts.Token); var t3 = turnstile.WaitAsync(); Assert.That(turnstile.HasWaiting); TaskAssert.DoesNotEnd(t1); TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); cts.Cancel(); Assert.That(turnstile.Turn()); TaskAssert.Completed(t1); TaskAssert.Cancelled(t2); TaskAssert.DoesNotEnd(t3); Assert.That(turnstile.Turn()); TaskAssert.Completed(t3); Assert.That(!turnstile.HasWaiting); Assert.That(!turnstile.Turn()); } }
public void WaitAsync_Exceeded_CanCedeTurn() { using (var cts = new CancellationTokenSource()) using (var quota = new Quota(1L)) { var t1 = quota.WaitAsync(); var t2 = quota.WaitAsync(cts.Token); var t3 = quota.WaitAsync(); Assert.That(quota.Balance, Is.EqualTo(-2L)); cts.Cancel(); Assert.That(quota.Balance, Is.EqualTo(-1L)); using (TaskAssert.Completed(t1)) { TaskAssert.Cancelled(t2); TaskAssert.DoesNotEnd(t3); } Assert.That(quota.Balance, Is.EqualTo(0L)); using (TaskAssert.Completed(t3)) { } Assert.That(quota.Balance, Is.EqualTo(1L)); } }
public void WaitAsync_WaitsForFire() { using (var trigger = new Trigger()) { var awaiter = trigger.WaitAsync(); TaskAssert.DoesNotEnd(awaiter); trigger.Fire(); TaskAssert.Completed(awaiter); } }
public void WaitAsync_Reset_WaitsForSet() { using (var cond = Condition.False()) { var awaiter = cond.WaitAsync(); TaskAssert.DoesNotEnd(awaiter); cond.Set(); TaskAssert.Completed(awaiter); } }
public void WaitAsync_NotEnded_WaitsForEnd() { using (var era = new Era()) { var awaiter = era.WaitAsync(); TaskAssert.DoesNotEnd(awaiter); era.End(); TaskAssert.Completed(awaiter); } }
public void WaitAsync_Reset_Cancelable() { using (var cts = new CancellationTokenSource()) using (var cond = Condition.False()) { var awaiter = cond.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); cts.Cancel(); TaskAssert.Cancelled(awaiter); } }
public void WaitAsync_DoesNotExist_Cancelable() { using (var cts = new CancellationTokenSource()) using (var future = new Future <int>()) { var awaiter = future.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); cts.Cancel(); TaskAssert.Cancelled(awaiter); } }
public void WaitAsync_Cancelable() { using (var cts = new CancellationTokenSource()) using (var evt = new Event <int>()) { var awaiter = evt.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); cts.Cancel(); TaskAssert.Cancelled(awaiter); } }
public void OrCanceledBy_NotCanceled_PropagatesResult() { using (var cts = new CancellationTokenSource()) { var tcs = new TaskCompletionSource <int>(); var cont = tcs.Task.OrCanceledBy(cts.Token); TaskAssert.DoesNotEnd(cont); tcs.TrySetResult(1); Assert.That(TaskAssert.Completed(cont), Is.EqualTo(1)); } }
public void Fire_Barrier() { using (var trigger = new Trigger()) { var before = trigger.WaitAsync(); trigger.Fire(); var after = trigger.WaitAsync(); TaskAssert.Completed(before); TaskAssert.DoesNotEnd(after); } }
public void WaitAsync_Cancelable() { using (var cts = new CancellationTokenSource()) using (var trigger = new Trigger()) { var awaiter = trigger.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); cts.Cancel(); TaskAssert.Cancelled(awaiter); } }
public void WaitAsync_NotEnded_Cancelable() { using (var cts = new CancellationTokenSource()) using (var era = new Era()) { var awaiter = era.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); cts.Cancel(); TaskAssert.Cancelled(awaiter); } }
public void WaitAsync_WaitsForPost() { using (var evt = new Event <int>()) { var awaiter = evt.WaitAsync(); TaskAssert.DoesNotEnd(awaiter); evt.Post(1); Assert.That( TaskAssert.Completed(awaiter), Is.EqualTo(1) ); } }
public void WaitAsync_DoesNotExist_WaitsForEnd() { using (var future = new Future <int>()) { var awaiter = future.WaitAsync(); TaskAssert.DoesNotEnd(awaiter); future.Post(1); Assert.That( TaskAssert.Completed(awaiter), Is.EqualTo(1) ); } }
public void WaitAsync_Acquired_WaitsForTurn() { using (var lck = new Lock()) { var t1 = TaskAssert.Detach(lck.WaitAsync); var t2 = TaskAssert.Detach(lck.WaitAsync); using (TaskAssert.Completed(t1)) { TaskAssert.DoesNotEnd(t2); } using (TaskAssert.Completed(t2)) { } } }
public void HasWaiting_DetectsCeded() { using (var cts = new CancellationTokenSource()) using (var turnstile = new Turnstile()) { var awaiter = turnstile.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); Assert.That(turnstile.HasWaiting); cts.Cancel(); TaskAssert.Cancelled(awaiter); Assert.That(!turnstile.HasWaiting); } }
public void WaitAsync_Acquired_Reenters() { using (var lck = new Lock()) { var h1 = TaskAssert.Completed(lck.WaitAsync()); var t1 = TaskAssert.Detach(lck.WaitAsync); var h2 = TaskAssert.Completed(lck.WaitAsync()); TaskAssert.DoesNotEnd(t1); h1.Dispose(); TaskAssert.DoesNotEnd(t1); h2.Dispose(); using (TaskAssert.Completed(t1)) { } } }
public void TrySkip_Empty_ReturnsTrueAndSkips() { using (var queue = new Queue()) { Assert.That(queue.TrySkip(out var handle)); var t1 = queue.WaitAsync(); using (handle) { TaskAssert.DoesNotEnd(t1); } using (TaskAssert.Completed(t1)) { } Assert.That(queue.IsEmpty); } }
public void WaitAsync_Synchronizes() { using (var barrier = new Barrier(3)) { var t1 = barrier.WaitAsync(); TaskAssert.DoesNotEnd(t1); Assert.That(barrier.WaitingFor, Is.EqualTo(2)); var t2 = barrier.WaitAsync(); TaskAssert.DoesNotEnd(t2); Assert.That(barrier.WaitingFor, Is.EqualTo(1)); var t3 = barrier.WaitAsync(); TaskAssert.Completed(t1); TaskAssert.Completed(t2); TaskAssert.Completed(t3); } }
public void WaitAsync_Waiting_CanRetract() { using (var cts = new CancellationTokenSource()) using (var barrier = new Barrier(3)) { var t1 = barrier.WaitAsync(); TaskAssert.DoesNotEnd(t1); Assert.That(barrier.WaitingFor, Is.EqualTo(2)); var t2 = barrier.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(t2); Assert.That(barrier.WaitingFor, Is.EqualTo(1)); cts.Cancel(); TaskAssert.Cancelled(t2); Assert.That(barrier.WaitingFor, Is.EqualTo(2)); } }
public void IsEmpty_DetectsCeded() { using (var cts = new CancellationTokenSource()) using (var queue = new Queue()) { var block = queue.WaitAsync(); var awaiter = queue.WaitAsync(cts.Token); TaskAssert.DoesNotEnd(awaiter); Assert.That(!queue.IsEmpty); cts.Cancel(); using (TaskAssert.Completed(block)) { } TaskAssert.Cancelled(awaiter); Assert.That(queue.IsEmpty); } }
public void WaitAsync_Acquired_CanCedeTurn() { using (var cts = new CancellationTokenSource()) using (var lck = new Lock()) { var t1 = TaskAssert.Detach(lck.WaitAsync); var t2 = TaskAssert.Detach(() => lck.WaitAsync(cts.Token)); var t3 = TaskAssert.Detach(lck.WaitAsync); TaskAssert.DoesNotEnd(t2); TaskAssert.DoesNotEnd(t3); cts.Cancel(); TaskAssert.Cancelled(t2); TaskAssert.DoesNotEnd(t3); using (TaskAssert.Completed(t1)) { } using (TaskAssert.Completed(t3)) { } } }