public void TestAddNull() { using (MultiWaiter <Task> waiter = new MultiWaiter <Task>()) { waiter.Add(null); } }
public void TestRemoveNull() { using (MultiWaiter <Task> waiter = new MultiWaiter <Task>()) { waiter.Remove(null); } }
public void TestMultiMoveNext() { using (MultiWaiter <Task> waiter = new MultiWaiter <Task>()) { waiter.WaitNextAsync(); waiter.WaitNextAsync().AwaitSynchronously(); } }
public void TestCompleteRemoved() { using (MultiWaiter <Task> waiter = new MultiWaiter <Task>()) { TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>(); waiter.Add(tcs1.Task); waiter.Remove(tcs1.Task); tcs1.SetResult(1); tcs1.Task.AwaitSynchronously(); Assert.IsFalse(waiter.WaitNextAsync().IsCompleted); } }
public void TestAddTwice() { using (MultiWaiter <Task> waiter = new MultiWaiter <Task>()) { Task t = new Task(() => { }); t.RunSynchronously(); Assert.IsTrue(waiter.Add(t)); Assert.IsFalse(waiter.Add(t)); Assert.AreEqual(t, waiter.WaitNextAsync().AwaitSynchronously()); Assert.IsTrue(waiter.Add(t)); Assert.IsFalse(waiter.Add(t)); } }
public void TestDispose() { MultiWaiter <Task> waiter = new MultiWaiter <Task>(); var waitForNextTask = waiter.WaitNextAsync(); Assert.IsFalse(waitForNextTask.IsCompleted); waiter.Dispose(); // Calling Dispose twice is allowed waiter.Dispose(); waitForNextTask.Wait(); Assert.IsTrue(waitForNextTask.IsCompleted); try { waiter.Add(new Task(() => { })); Assert.Fail(); } catch (ObjectDisposedException) { } try { waiter.Remove(new Task(() => { })); Assert.Fail(); } catch (ObjectDisposedException) { } try { waiter.WaitNextAsync().AwaitSynchronously(); Assert.Fail(); } catch (ObjectDisposedException) { } }
public void TestSimple() { using (MultiWaiter <Task> waiter = new MultiWaiter <Task>()) { var waitForNextTask = waiter.WaitNextAsync(); TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>(); TaskCompletionSource <int> tcs2 = new TaskCompletionSource <int>(); TaskCompletionSource <int> tcs3 = new TaskCompletionSource <int>(); waiter.Add(tcs1.Task); waiter.Add(tcs2.Task); waiter.Add(tcs3.Task); Assert.IsFalse(waitForNextTask.IsCompleted); tcs1.SetResult(1); var completedTask = waitForNextTask.AwaitSynchronously(); Assert.AreSame(tcs1.Task, completedTask); waitForNextTask = waiter.WaitNextAsync(); Assert.IsFalse(waitForNextTask.IsCompleted); } }