public async static Task <TcpReceiver> Receive(int port) { var receiver = new TcpReceiver(port); await receiver.Start(); return(receiver); }
public async void Reconnects_when_connection_closes() { using (var receiver = await TcpReceiver.Receive(_port)) { _sender = CreateSender(); _sender.OnNext(new FormattedLogEvent { Content = "Hello1" }); await Task.Delay(50); Assert.Equal("Hello1", receiver.Lines.Single()); await receiver.ResetSocket(); } using (var receiver = await TcpReceiver.Receive(_port)) { _sender.OnNext(new FormattedLogEvent { Content = "Hello2" }); await Task.Delay(1500); //enough time for sender to retry Assert.Equal("Hello2", receiver.Lines.Single()); } }
public async void Sends_content_to_tcp_endpoint() { using (var receiver = await TcpReceiver.Receive(_port)) { _sender = CreateSender(); _sender.OnNext(new FormattedLogEvent { Content = "Hello1" }); await Task.Delay(100); Assert.Equal("Hello1", receiver.Lines.Single()); } }
public async Task Copes_under_parallel_load() { using (var receiver = await TcpReceiver.Receive(_port)) { _sender = CreateSender(); var messages = Enumerable.Range(0, 5000) .Select(i => i.ToString()) .ToArray(); Parallel.ForEach(messages, m => { _sender.OnNext(new FormattedLogEvent { Content = m }); }); await Task.Delay(2000); var received = new HashSet <string>(receiver.Lines); Assert.All(messages, m => received.Contains(m)); } }