Example #1
0
    public async Task Test4ThensAsync500MsEach2000MsTotal()
    {
        // Start the runner asynchronously.
        Task t = Runner.Run(S).Then(S, S, S).Async();

        // Take a lap right away. This should be only a few milliseconds in
        // if the runner tasks really started asynchronously.
        Laps.Add(Lapper.Lap());
        // Wait for all of the runner tasks to finish.
        await t.ConfigureAwait(false);

        Lapper.Stop();
        // There should be 5 laps; one that we took right away and one each per runner task.
        Assert.Equal(5, Laps.Count);
        // The first task should have been lapped right away, a few milliseconds after starting.
        // Let's give a 500% epsilon since the expected time is so short.
        TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(10), Lapper.Laps[0], 5);
        // The rest should each take about 500ms.
        foreach (var lap in Laps.Skip(1))
        {
            TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1);
        }
        // ... And the total time should have been about 4 x 500ms = 2000ms.
        TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(2000), Lapper.Elapsed, 0.1);
    }
Example #2
0
    public async Task Test4AndsAsync500MsEach500MsTotal()
    {
        // Start the runner asynchronously.
        Task t = Runner.Run(S).And(S, S, S).Async();

        // Take a lap right away. This should be only a few milliseconds in
        // if the runner tasks really started asynchronously.
        Laps.Add(Lapper.Lap());
        // Wait for the runner to finish.
        await t.ConfigureAwait(false);

        Lapper.Stop();
        // The async lap (first lap) should have been only a few ms after its stopwatch started.
        TimeAssert.EpsilonEquals(TimeSpan.FromMilliseconds(25), Laps[0], TimeSpan.FromMilliseconds(50));
        // We should have one lap per task run.
        Assert.Equal(5, Laps.Count);
        // Each lap should be about 500ms...
        // Skip the first lap because it was the one we took right away.
        foreach (TimeSpan lap in Laps.Skip(1))
        {
            TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1);
        }
        // And the elapsed time should be 500ms since the tasks were all run in parallel.
        TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), Lapper.Elapsed, 0.1);
    }
Example #3
0
 public void Test4ThensSync500MsEach2000MsTotal()
 {
     // Run the four runner tasks synchronously.
     Runner.Run(S).Then(S, S, S).Sync();
     // Stop the timer after the four tasks have finished.
     Lapper.Stop();
     // We should have four laps since we ran four tasks.
     Assert.Equal(4, Laps.Count);
     // Each lap should have been about 500ms...
     foreach (var lap in Laps)
     {
         TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1);
     }
     // ... And the total time should have been 4 x 500ms = 2000ms.
     TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(2000), Lapper.Elapsed, 0.1);
 }
Example #4
0
 public void Test4AndsSync500MsEach500MsTotal()
 {
     // Execute the runner synchronously.
     Runner.Run(S).And(S, S, S).Sync();
     // Take a lap once the runner is finished.
     Lapper.Stop();
     // We should have one lap per task run.
     Assert.Equal(4, Laps.Count);
     // Each lap should be about 500ms...
     foreach (TimeSpan lap in Laps)
     {
         TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), lap, 0.1);
     }
     // ... And the total time should also be about 500ms since we ran all four tasks in parallel.
     TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), Lapper.Elapsed, 0.1);
 }
Example #5
0
 public void TestThenDelaySync100MsEach500MsTotal()
 {
     Runner.Run(100).Then(100).Then(100).Then(100).Then(100).Sync();
     Lapper.Stop();
     TimeAssert.DeltaEquals(TimeSpan.FromMilliseconds(500), Lapper.Elapsed, 0.25);
 }