public void ThrowException_WhenTryingToStartItWithDifferentClientWhileItIsWorking() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(5000)); dog.Start(tcpClientMock.Object); Assert.Throws <AdminPortException>(() => dog.Start(Mock.Of <IAdminPortTcpClient>())); }
public void Disconnect() { ConnectionWatchdog.Stop(); Reader.Close(); Writer.Close(); TcpClient.Close(); }
private static void OnClose(WebSocketCloseCode closecode) { Disconnect(closecode.ToString()); // Notify ConnectionWatchdog that connection was lost ConnectionWatchdog.OnClose(closecode); }
private void Init(IPAddress ip, int port, int watchdogPollMs) { Ip = ip; Port = port; ConnectionWatchdog = new(watchdogPollMs); ConnectionWatchdog.Elapsed += ConnectionWatchdogTick; ConnectionWatchdog.Start(); }
public async Task ErrorOut_IfServerDoesNotRespondInTime() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(0.2)); Exception e = null; dog.Errored += (_, ex) => e = ex; dog.Start(tcpClientMock.Object); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.NotNull(e); Assert.False(dog.Enabled); }
public async Task NotErrorOut_AfterWatchdogIsStopped() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(0.1)); Exception e = null; dog.Errored += (_, ex) => e = ex; dog.Start(tcpClientMock.Object); dog.Stop(); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.Null(e); Assert.False(dog.Enabled); }
private static void OnOpen() { // Notify ConnectionWatchdog that connection is ok ConnectionWatchdog.OnOpen(); // observable FoolObservable.OnConnectedToGameServer(); IsConnectingToGameServer = false; IsConnected = true; //authorize with token ClientSendPackets.Send_Authorize(myToken); }
public async Task ErrorOut_WhenPongMsgArgumentIsNotMatchingPing() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(0.1)); Exception e = null; dog.Errored += (_, ex) => e = ex; tcpClientMock.Setup(x => x.SendMessage(It.IsAny <IAdminMessage>())) .Callback((IAdminMessage msg) => { var pingMsg = (AdminPingMessage)msg; var pongMsg = new AdminServerPongMessage(pingMsg.Argument + 1); tcpClientMock.Object.SimulateMessageReceived(pongMsg); }); dog.Start(tcpClientMock.Object); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.NotNull(e); Assert.False(dog.Enabled); }
public async Task BeAbleToStartAgain_AndWorkCorrect() { var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(0.1)); Exception e = null; dog.Errored += (_, ex) => e = ex; dog.Start(tcpClientMock.Object); dog.Stop(); dog.Start(tcpClientMock.Object); tcpClientMock.Setup(x => x.SendMessage(It.IsAny <IAdminMessage>())) .Callback((IAdminMessage msg) => { var pingMsg = (AdminPingMessage)msg; var pongMsg = new AdminServerPongMessage(pingMsg.Argument); tcpClientMock.Object.SimulateMessageReceived(pongMsg); }); await Task.Delay(TimeSpan.FromSeconds(1)); Assert.Null(e); Assert.True(dog.Enabled); }
public void Stop() { ShouldExit = true; ConnectionWatchdog.Join(); }
public AmeisenNavigationHandler(string ip, int port) { Client = new(ip, port); ConnectionWatchdog = new(ObserveConnection); ConnectionWatchdog.Start(); }
public DefaultChannelInitializer(ConnectionWatchdog watchdog) { this.watchdog = watchdog; }
public void RequestDisconnect() { ShouldExit = true; ConnectionWatchdog.Join(); }