public override async Task SendMessages(IBus bus, Func <bool> shouldKeepSending) { while (shouldKeepSending()) { var response = await bus.Request(new FooRequest()); IncrementExpectedMessageCount(); StressTestMessageHandler.RecordResponseMessageReceipt(response); } }
protected virtual async Task When() { Log.Information("Starting to send messages..."); StressTestMessageHandler.Reset(); _sendingStopwatch = Stopwatch.StartNew(); _sendingAndReceivingStopwatch = Stopwatch.StartNew(); await Enumerable.Range(0, 20) .Select(i => Task.Run(() => SendMessages(Bus, ShouldKeepSending)).ConfigureAwaitFalse()) .WhenAll(); _sendingStopwatch.Stop(); Log.Information("Total of {NumMessagesSent} messages sent in {Elapsed}", _numMessagesSent, _sendingStopwatch.Elapsed); await StressTestMessageHandler.WaitUntilDone(_numMessagesSent, TimeSpan.FromSeconds(TimeoutSeconds)); _sendingAndReceivingStopwatch.Stop(); }