Esempio n. 1
0
        public void NotThrowsBeforeTimeoutNonGeneric()
        {
            var t1 = TestTasks.ProcessTask(TimeSpan.FromSeconds(2), 0);

            Assert.DoesNotThrowAsync(async() =>
                                     await t1.WithTimeout(TimeSpan.FromSeconds(5)));
        }
Esempio n. 2
0
        public void ThrowsOnTimeoutNonGeneric()
        {
            var t1 = TestTasks.ProcessTask(TimeSpan.FromSeconds(5), 0);

            Assert.ThrowsAsync <TaskCanceledException>(async() =>
                                                       await t1.WithTimeout(TimeSpan.FromSeconds(2)));
        }
Esempio n. 3
0
        public void ThrowsTimeoutExceptionBeforeArgument()
        {
            var t1 = TestTasks.GetResult(TimeSpan.FromSeconds(5), 2);

            Assert.ThrowsAsync <TaskCanceledException>(async() =>
                                                       await t1.WithTimeout(TimeSpan.FromSeconds(2)));
        }
Esempio n. 4
0
        public void ThrowsRightExceptionBeforeTimeout()
        {
            var t1 = TestTasks.GetResult(TimeSpan.FromSeconds(2), 1);

            Assert.ThrowsAsync <ArgumentException>(async() =>
                                                   await t1.WithTimeout(TimeSpan.FromSeconds(1)));
        }
Esempio n. 5
0
        public void NotThrowsBeforeTimeout()
        {
            var t1 = TestTasks.GetResult(TimeSpan.FromSeconds(2), 0);

            Assert.DoesNotThrowAsync(async() =>
                                     await t1.WithTimeout(TimeSpan.FromSeconds(5)));
        }
Esempio n. 6
0
        public async Task CompletedInRightOrderNaive(int tm1, int tm2, int tm3)
        {
            var t1    = TestTasks.GetInt(tm1);
            var t2    = TestTasks.GetInt(tm2);
            var t3    = TestTasks.GetInt(tm3);
            var tasks = new Task <int>[] { t1, t2, t3 };

            var resultArray = new int[3];
            int idx         = 0;

            foreach (var t in tasks)
            {
                try
                {
                    var res = await t;
                    resultArray[idx++] = res;
                }
                catch (Exception)
                {
                    resultArray[idx++] = -1;
                }
            }

            if (tm1 > 0)
            {
                Assert.AreEqual(tm1, resultArray[0]);
            }
            else
            {
                Assert.AreEqual(-1, resultArray[0]);
            }

            if (tm2 > 0)
            {
                Assert.AreEqual(tm2, resultArray[1]);
            }
            else
            {
                Assert.AreEqual(-1, resultArray[1]);
            }

            if (tm3 > 0)
            {
                Assert.AreEqual(tm3, resultArray[2]);
            }
            else
            {
                Assert.AreEqual(-1, resultArray[2]);
            }
        }
Esempio n. 7
0
        public async Task CompletedInRightOrder(int tm1, int tm2, int tm3)
        {
            var t1    = TestTasks.GetInt(tm1);
            var t2    = TestTasks.GetInt(tm2);
            var t3    = TestTasks.GetInt(tm3);
            var tasks = new Task <int>[] { t1, t2, t3 };

            var testArray = new int[] { tm1, tm2, tm3 };

            testArray = testArray.OrderBy(i => Math.Abs(i)).ToArray();

            var resultArray = new int[3];
            int idx         = 0;

            foreach (var t in tasks.InCompletionOrder())
            {
                try
                {
                    var res = await t;
                    resultArray[idx++] = res;
                }
                catch (Exception)
                {
                    resultArray[idx++] = -1;
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (testArray[i] > 0)
                {
                    Assert.AreEqual(testArray[i], resultArray[i]);
                }
                else
                {
                    Assert.AreEqual(-1, resultArray[i]);
                }
            }
        }