//[DotMemoryUnit(SavingStrategy = )] public void PingPong() { Stopwatch watch = Stopwatch.StartNew(); for (var i = 0; i < _count; i++) { _channelToServer.Post(new TextMessage { Text = "Hello, server!" }); } GCStats before = GCStats.Snapshot(); for (var times = 0; times < 120; times++) { if (_testCompleted.WaitOne(TimeSpan.FromSeconds(1))) { break; } Console.WriteLine($"{times:D3}: Server={_serverReceived.ToString(CultureInfo.InvariantCulture)} Client={_clientReceived.ToString(CultureInfo.InvariantCulture)} messages."); } watch.Stop(); GCStats diff = before.Diff(); var expected = new { Client = _clientReceived, Server = _serverReceived }; var actual = new { Client = _count, Server = _count }; Console.WriteLine(diff); expected.Should().BeEquivalentTo(actual); Console.WriteLine($"Finished in {watch.ElapsedMilliseconds:N3} ms, perf {_count * 1000.0 / watch.ElapsedMilliseconds:N} msg/sec"); }
public void Should_deliver_a_bunch_of_messages_to_server() { _channelToServer.Post(new TextMessage { Text = $"Hello {(-1).ToString(CultureInfo.InvariantCulture)}, server !" }); Stopwatch watch = Stopwatch.StartNew(); for (var i = 0; i < _count; i++) { _channelToServer.Post(new TextMessage { Text = $"Hello {i.ToString(CultureInfo.InvariantCulture)}, server !" }); } Console.WriteLine($"Pushed all messages in {watch.ElapsedMilliseconds}"); GCStats before = GCStats.Snapshot(); for (var times = 0; times < 60; times++) { if (_allMessagesReceived.WaitOne(TimeSpan.FromSeconds(1))) { break; } Console.WriteLine($"{times:D3}: received {_serverReceived.ToString(CultureInfo.InvariantCulture)} messages."); } watch.Stop(); GCStats diff = before.Diff(); Console.WriteLine($"Finished in {watch.ElapsedMilliseconds:N3} ms, perf {_count * 1000.0 / watch.ElapsedMilliseconds:N} msg/sec"); Console.WriteLine(diff); _serverReceived.Should().Be(_count + 1); }