Example #1
0
        public void ThrowException_WhenTryingToStartItWithDifferentClientWhileItIsWorking()
        {
            var dog = new ConnectionWatchdog(TimeSpan.FromSeconds(5000));

            dog.Start(tcpClientMock.Object);
            Assert.Throws <AdminPortException>(() => dog.Start(Mock.Of <IAdminPortTcpClient>()));
        }
Example #2
0
 public void Disconnect()
 {
     ConnectionWatchdog.Stop();
     Reader.Close();
     Writer.Close();
     TcpClient.Close();
 }
Example #3
0
        private static void OnClose(WebSocketCloseCode closecode)
        {
            Disconnect(closecode.ToString());

            // Notify ConnectionWatchdog that connection was lost
            ConnectionWatchdog.OnClose(closecode);
        }
Example #4
0
        private void Init(IPAddress ip, int port, int watchdogPollMs)
        {
            Ip = ip;
            Port = port;

            ConnectionWatchdog = new(watchdogPollMs);
            ConnectionWatchdog.Elapsed += ConnectionWatchdogTick;
            ConnectionWatchdog.Start();
        }
Example #5
0
        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);
        }
Example #6
0
        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);
        }
Example #7
0
        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);
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
 public void Stop()
 {
     ShouldExit = true;
     ConnectionWatchdog.Join();
 }
Example #11
0
 public AmeisenNavigationHandler(string ip, int port)
 {
     Client             = new(ip, port);
     ConnectionWatchdog = new(ObserveConnection);
     ConnectionWatchdog.Start();
 }
Example #12
0
 public DefaultChannelInitializer(ConnectionWatchdog watchdog)
 {
     this.watchdog = watchdog;
 }
 public void RequestDisconnect()
 {
     ShouldExit = true;
     ConnectionWatchdog.Join();
 }