public async Task StartAsync(CancellationToken cancellationToken) { try { _keepAlive.Start(); _subscriptionReplier.Start(cancellationToken); await _subscriptionReceiver .StartAsync(cancellationToken) .ConfigureAwait(false); } finally { await _context.CloseAsync().ConfigureAwait(false); } }
public async Task AfterTimeout_ReceiveKeepAlive() { // arrange var timeout = TimeSpan.FromMilliseconds(100); (WebSocketContext context, WebSocketMock socket) = WebSocketContextHelper.Create(); var keepAlive = new WebSocketKeepAlive( context, timeout, new CancellationTokenSource()); // act keepAlive.Start(); await Task.Delay(timeout.Add(TimeSpan.FromMilliseconds(500))); // assert Assert.True(socket.Outgoing.Any(t => t.Type.Equals(MessageTypes.Connection.KeepAlive))); }