public void TestAllPassOnBasicRun()
        {
            var numTasks = 10;
            var funcs    = TestFunctionBuilder.CreateMany(numTasks);

            var runner  = new ConcurrentFunctionRunner(2);
            var results = runner.Run(funcs);

            // Check there is the expected number of results returned.
            Assert.IsTrue(results.Length == numTasks);

            // Check that they have all succeeded.
            Assert.IsTrue(results.All(_ => _.IsSucc()));
        }
        public void TestNumThreadsCreated()
        {
            Console.WriteLine($"Start Threads = {System.Diagnostics.Process.GetCurrentProcess().Threads.Count}");

            var numTasks = 150;
            var runner   = new ConcurrentFunctionRunner(5);

            var funcs   = TestFunctionBuilder.CreateMany(numTasks);
            var results = runner.Run(funcs);

            Assert.IsTrue(results.Length == numTasks);
            Assert.IsTrue(results.All(_ => _.IsSucc()));

            Console.WriteLine($"End Threads = {System.Diagnostics.Process.GetCurrentProcess().Threads.Count}");
        }
Ejemplo n.º 3
0
        public void TestThreeTupleResultsAreInCorrectOrder()
        {
            var runner = new ConcurrentFunctionRunner(3);

            // Using the Tuple extension methods.
            var(firstCall, secondCall, thirdCall) = runner.Run(() => 1, () => 2, () => 3);

            Assert.IsTrue(firstCall.IsSucc());
            Assert.AreEqual(firstCall.GetValue(), 1);

            Assert.IsTrue(secondCall.IsSucc());
            Assert.AreEqual(secondCall.GetValue(), 2);

            Assert.IsTrue(thirdCall.IsSucc());
            Assert.AreEqual(thirdCall.GetValue(), 3);
        }
        public void TestResultsReturnedInSameOrder()
        {
            var numTasks = 20;
            var runner   = new ConcurrentFunctionRunner(3);

            var funcs   = TestFunctionBuilder.CreateMany(numTasks);
            var results = runner.Run(funcs);

            Assert.IsTrue(results.Length == numTasks);
            Assert.IsTrue(results.All(_ => _.IsSucc()));

            // Get all the result values.
            var values = results.AllOrFirstFail().GetValue().ToArray();

            // Check the index of each result, and check against it's return value to ensure
            // that the order of the returned results is the same as the order the tasks were sent.
            for (int idx = 0; idx < values.Length; idx++)
            {
                Assert.AreEqual(values[idx], idx * 5, $"Got {values[idx]}, Expected {idx * 5}");
            }
        }