/// <summary> /// Wait for a specified timeout that a client enters the <see cref="wantedState"/> /// </summary> /// <param name="clientIdx">Client to watch</param> /// <param name="timeToWait">Time out to wait</param> /// <param name="wantedState">The state the client shall enter</param> protected void WaitForConnectionState(int clientIdx, TimeSpan timeToWait, BinaryConnectionState wantedState) { Console.WriteLine($"WaitForConnectionState. ClientIdx: {clientIdx}, wanted state: {wantedState:G}"); var timeout = DateTime.Now.Add(timeToWait); var start = DateTime.Now; var waitedFor = new TimeSpan(); while (!_clients[clientIdx].Connection.CurrentState.Equals(wantedState) && timeout > DateTime.Now) { Thread.Sleep(new TimeSpan(0, 0, 0, 0, 100)); waitedFor = DateTime.Now.Subtract(start); } // Client should be connected Assert.AreEqual(wantedState, _clients[clientIdx].Connection.CurrentState, $"Client ({clientIdx}) is not in the state '{wantedState:G}'. " + $"CurrentState: {_clients[clientIdx].Connection.CurrentState:G}. Waited for {waitedFor:g}"); }
/// <summary> /// Wait for a specified timeout that a client enters the <see cref="wantedState"/> /// </summary> /// <param name="clientIdx">Client to watch</param> /// <param name="timeToWait">Time out to wait</param> /// <param name="wantedState">The state the client shall enter</param> protected void WaitForConnectionState(int clientIdx, TimeSpan timeToWait, BinaryConnectionState wantedState) { Console.WriteLine($"WaitForConnectionState. ClientIdx: {clientIdx}, wanted state: {wantedState:G}"); var stopWatch = new Stopwatch(); stopWatch.Start(); while (!_clients[clientIdx].Connection.CurrentState.Equals(wantedState) && stopWatch.ElapsedMilliseconds < timeToWait.TotalMilliseconds) { Thread.Sleep(new TimeSpan(0, 0, 0, 0, 100)); } stopWatch.Stop(); // Client should be connected Assert.AreEqual(wantedState, _clients[clientIdx].Connection.CurrentState, $"Client ({clientIdx}) is not in the state '{wantedState:G}'. " + $"CurrentState: {_clients[clientIdx].Connection.CurrentState:G}. Waited for {stopWatch.ElapsedMilliseconds/1000}s"); }
protected ClientStateBase(TcpClientConnection context, StateMap stateMap, BinaryConnectionState connectionState) : base(context, stateMap) { Current = connectionState; }
protected ServerStateBase(TcpListenerConnection context, StateMap stateMap, BinaryConnectionState connectionState) : base(context, stateMap) { CurrentState = connectionState; }