Ejemplo n.º 1
0
        public void TimeoutNeverOccurs()
        {
            ITasks sut  = new SyncTasks();
            var    task = sut.StartNew(() => Thread.Sleep(TimeSpan.FromSeconds(1)));

            sut.WaitAll(new Task[] { task }, TimeSpan.FromSeconds(0.1));
        }
Ejemplo n.º 2
0
        public void InvokingWaitAllMultipleTimesDoesntInvokeActionMultipleTimes()
        {
            ITasks sut     = new SyncTasks();
            var    counter = 0;
            var    task    = sut.StartNew(() => { counter++; });

            sut.WaitAll(task);
            sut.WaitAll(task);
            sut.WaitAll(task, task);
            Assert.AreEqual(1, counter);
        }
Ejemplo n.º 3
0
        void TestSyncTasks(Action <ITasks, Task> waitAll)
        {
            ITasks sut      = new SyncTasks();
            var    done     = false;
            var    threadId = Thread.CurrentThread.ManagedThreadId;
            var    task     = sut.StartNew(() =>
            {
                Assert.AreEqual(threadId, Thread.CurrentThread.ManagedThreadId);
                done = true;
            });

            Assert.IsFalse(done);
            waitAll(sut, task);
            Assert.IsTrue(done);
        }