Exemple #1
0
 public void TestMultiMoveNext()
 {
     using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
     {
         waiter.WaitNextAsync();
         waiter.WaitNextAsync().AwaitSynchronously();
     }
 }
Exemple #2
0
        public void TestRemoveUncompleted()
        {
            using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
            {
                TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>();
                TaskCompletionSource <int> tcs2 = new TaskCompletionSource <int>();

                waiter.Add(tcs1.Task);
                waiter.Add(tcs2.Task);

                waiter.Remove(tcs1.Task);

                tcs2.SetResult(1);

                Task t = waiter.WaitNextAsync().AwaitSynchronously();
                Assert.AreSame(tcs2.Task, t);

                Assert.IsFalse(waiter.WaitNextAsync().IsCompleted);
            }
        }
Exemple #3
0
        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)
            { }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        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));
            }
        }
Exemple #6
0
        public void TestCompleteRemoved2()
        {
            using (MultiWaiter <Task> waiter = new MultiWaiter <Task>())
            {
                TaskCompletionSource <int> tcs1 = new TaskCompletionSource <int>();

                waiter.Add(tcs1.Task);

                tcs1.SetResult(1);
                tcs1.Task.AwaitSynchronously();

                waiter.Remove(tcs1.Task);

                Assert.IsFalse(waiter.WaitNextAsync().IsCompleted);
            }
        }