public void Should_not_account_for_requests_still_in_progress() { var tcs = new TaskCompletionSource <ClusterResult>(); var tasks = new List <Task <ClusterResult> >(); for (var i = 0; i < 500; i++) { tasks.Add(module.ExecuteAsync(context, _ => tcs.Task)); } module.Requests.Should().Be(0); module.Accepts.Should().Be(0); tcs.TrySetResult(rejectedResult); foreach (var task in tasks) { task.GetAwaiter().GetResult().Should().BeSameAs(rejectedResult); } module.Requests.Should().Be(500); module.Accepts.Should().Be(0); Console.Out.WriteLine(module.RejectionProbability); }
private ClusterResult Execute(ClusterResult result) { return(module.ExecuteAsync(context, _ => Task.FromResult(result)).GetAwaiter().GetResult()); }