public void Task_OneSyncContext()
        {
            string testName = "Task_OneSyncContext";

            var baseline = DoBaseTestRun(testName + "-Baseline", numTasks);

            var syncContext = new AsyncTestContext(output);
            SynchronizationContext.SetSynchronizationContext(syncContext);

            var tasks = new List<Task>(numTasks);

            QueuedTaskSchedulerTests_Set1.TimeRun(1, baseline, testName, output, () =>
            {
                for (int i = 0; i < numTasks; i++)
                {
                    Task t = CreateTask(i);
                    t.Start();
                    tasks.Add(t);
                }

                Task.WaitAll(tasks.ToArray());
            });

            foreach (Task t in tasks)
            {
                Assert.IsTrue(t.IsCompleted, "Task is completed");
                Assert.IsFalse(t.IsFaulted, "Task did not fault");
                Assert.IsNull(t.Exception, "Task did not return an Exception");
            }
        }
Example #2
0
        public void Task_OneSyncContext()
        {
            string testName = "Task_OneSyncContext";

            var baseline = DoBaseTestRun(testName + "-Baseline", numTasks);

            var syncContext = new AsyncTestContext();

            SynchronizationContext.SetSynchronizationContext(syncContext);

            var tasks = new List <Task>(numTasks);

            QueuedTaskSchedulerTests_Set1.TimeRun(1, baseline, testName, () =>
            {
                for (int i = 0; i < numTasks; i++)
                {
                    Task t = CreateTask(i);
                    t.Start();
                    tasks.Add(t);
                }

                Task.WaitAll(tasks.ToArray());
            });

            foreach (Task t in tasks)
            {
                Assert.IsTrue(t.IsCompleted, "Task is completed");
                Assert.IsFalse(t.IsFaulted, "Task did not fault");
                Assert.IsNull(t.Exception, "Task did not return an Exception");
            }
        }
Example #3
0
        public void Sched_Task_OnCompletion()
        {
            var asyncContext = new AsyncTestContext();
            int numActions   = 0;

            Action action = () =>
            {
                Console.WriteLine("Action");
                numActions++;
            };

            SynchronizationContext.SetSynchronizationContext(asyncContext);

            Task t = Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());

            t.Wait();

            Assert.AreEqual(1, asyncContext.NumOperationsStarted, "AsynContext.OperationStarted");
            Assert.AreEqual(1, asyncContext.NumOperationsCompleted, "AsynContext.OperationCompleted");
            Assert.AreEqual(1, numActions, "Actions");
        }
        public void Sched_Task_OnCompletion()
        {
            var asyncContext = new AsyncTestContext(output);
            int numActions = 0;

            Action action = () =>
            {
                output.WriteLine("Action");
                numActions++;
            };

            SynchronizationContext.SetSynchronizationContext(asyncContext);

            Task t = Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
            t.Wait();

            Assert.AreEqual(1, asyncContext.NumOperationsStarted, "AsynContext.OperationStarted");
            Assert.AreEqual(1, asyncContext.NumOperationsCompleted, "AsynContext.OperationCompleted");
            Assert.AreEqual(1, numActions, "Actions");
        }