public async Task SingleTask(int duration, int tolerance) { var time = await TimedTask(async() => { var pts = new ParallelTokenSource(); var token = pts.CreateToken(); _ = Task.Run(async() => { await Task.Delay(duration); token.Complete(); }); await pts.WaitForCompletion(); }); Assert.InRange(time.TotalMilliseconds, duration - tolerance, duration + tolerance); }
public async Task MultiExecution(int waitTime, int interval, int tolerance) { var time = await TimedTask(async() => { var pts = new ParallelTokenSource(); for (int i = waitTime; i > 0; i -= interval) { var current = i; var token = pts.CreateToken(); _ = Task.Run(async() => { await Task.Delay(current); token.Complete(); }); } await pts.WaitForCompletion(); }); Assert.InRange(time.TotalMilliseconds, waitTime - tolerance, waitTime + tolerance); }