public async Task OnAttached_ClearsAckQueue() { var client = GetDisconnectedClient(); client.State.WaitingForAck.Add(new MessageAndCallback(new ProtocolMessage(), null)); client.ExecuteCommand(SetClosedStateCommand.Create()); await client.ProcessCommands(); // Wait for the command to be executed client.State.WaitingForAck.Should().BeEmpty(); }
public async Task OnAttached_ShouldDestroyTranspоrt() { var client = await GetConnectedClient(); client.ConnectionManager.Transport.Should().NotBeNull(); client.ExecuteCommand(SetClosedStateCommand.Create()); await client.ProcessCommands(); client.ConnectionManager.Transport.Should().BeNull(); }
public override async Task <bool> OnMessageReceived(ProtocolMessage message, RealtimeState state) { switch (message.Action) { case ProtocolMessage.MessageAction.Auth: Context.ExecuteCommand(RetryAuthCommand.Create(false).TriggeredBy("ConnectedState.OnMessageReceived()")); return(true); case ProtocolMessage.MessageAction.Connected: Context.ExecuteCommand(SetConnectedStateCommand.Create(message, isUpdate: true).TriggeredBy("ConnectedState.OnMessageReceived()")); return(true); case ProtocolMessage.MessageAction.Close: Context.ExecuteCommand(SetClosedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()")); return(true); case ProtocolMessage.MessageAction.Disconnected: if (message.Error?.IsTokenError ?? false) { if (Context.ShouldWeRenewToken(message.Error, state)) { Context.ExecuteCommand(RetryAuthCommand.Create(message.Error, true).TriggeredBy("ConnectedState.OnMessageReceived()")); } else { Context.ExecuteCommand(SetFailedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()")); } return(true); } Context.ExecuteCommand(SetDisconnectedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()")); return(true); case ProtocolMessage.MessageAction.Error: // an error message may signify an error state in the connection or in a channel // Only handle connection errors here. if (message.Channel.IsEmpty()) { Context.ExecuteCommand(SetFailedStateCommand.Create(message.Error).TriggeredBy("ConnectedState.OnMessageReceived()")); } return(true); } return(false); }
public override Task <bool> OnMessageReceived(ProtocolMessage message, RealtimeState state) { switch (message.Action) { case ProtocolMessage.MessageAction.Closed: TransitionState(SetClosedStateCommand.Create().TriggeredBy("ClosingState.OnMessageReceived()")); return(Task.FromResult(true)); case ProtocolMessage.MessageAction.Disconnected: TransitionState(SetDisconnectedStateCommand.Create(message.Error).TriggeredBy("ClosingState.OnMessageReceived()")); return(Task.FromResult(true)); case ProtocolMessage.MessageAction.Error: TransitionState(SetFailedStateCommand.Create(message.Error).TriggeredBy("ClosingState.OnMessageReceived()")); return(Task.FromResult(true)); } return(Task.FromResult(false)); }
public async Task WithClosedOrFailedConnectionStates_ShouldReturnError() { var client = GetClientWithFakeTransport(); client.Workflow.QueueCommand(SetClosedStateCommand.Create(new ErrorInfo())); await client.WaitForState(ConnectionState.Closed); var result = await client.Connection.PingAsync(); result.IsSuccess.Should().BeFalse(); result.Error.Should().Be(PingRequest.DefaultError); client.Workflow.QueueCommand(SetFailedStateCommand.Create(new ErrorInfo())); await client.WaitForState(ConnectionState.Failed); var resultFailed = await client.Connection.PingAsync(); resultFailed.IsSuccess.Should().BeFalse(); resultFailed.Error.Should().Be(PingRequest.DefaultError); }
private void OnTimeOut() { Context.ExecuteCommand(SetClosedStateCommand.Create().TriggeredBy("ClosingState.OnTimeOut()")); }
public override void Close() { _timer.Abort(); Context.ExecuteCommand(SetClosedStateCommand.Create().TriggeredBy("SuspendedState.Close()")); }
public override void Close() { AbortTimer(); Context.ExecuteCommand(SetClosedStateCommand.Create().TriggeredBy("DisconnectedState.Close()")); }