Exemplo n.º 1
0
        public void MakeItFasterTest()
        {
            int[]     delays = new int[] { 5_000, 10_000, 1_000, 2_000, 4_000, 6_000 };
            bool[]    run    = Enumerable.Repeat(false, 6).ToArray();
            Stopwatch sw     = Stopwatch.StartNew();

            Threading.MakeItFaster(
                () => { Task.Delay(delays[0]).Wait(); run[0] = true; },
                () => { Task.Delay(delays[1]).Wait(); run[1] = true; },
                () => { Task.Delay(delays[2]).Wait(); run[2] = true; },
                () => { Task.Delay(delays[3]).Wait(); run[3] = true; },
                () => { Task.Delay(delays[4]).Wait(); run[4] = true; },
                () => { Task.Delay(delays[5]).Wait(); run[5] = true; }
                );
            long elapsed = sw.ElapsedMilliseconds;

            Assert.IsTrue(run.All(b => b));
            Assert.IsTrue(Math.Abs(elapsed - 10_000) < 2000);
        }