コード例 #1
0
            public async Task OnAttached_ClearsAckQueue()
            {
                var client = GetDisconnectedClient();

                client.State.WaitingForAck.Add(new MessageAndCallback(new ProtocolMessage(), null));

                client.ExecuteCommand(SetSuspendedStateCommand.Create(null));

                await client.ProcessCommands(); // Wait for the command to be executed

                client.State.WaitingForAck.Should().BeEmpty();
            }
コード例 #2
0
        WhenOperatingSystemNetworkBecomesAvailableAndStateIsSuspended_ShouldTransitionTryToConnectImmediately(Protocol protocol)
        {
            var client = await GetRealtimeClient(protocol, (options, _) => options.AutoConnect = false);

            client.Connection.On(stateChange => Output.WriteLine("State Changed: " + stateChange.Current + " From: " + stateChange.Previous));
            client.Connect();

            await WaitToBecomeConnected(client);

            client.Workflow.QueueCommand(SetSuspendedStateCommand.Create(ErrorInfo.ReasonSuspended));

            await client.WaitForState(ConnectionState.Suspended);

            Connection.NotifyOperatingSystemNetworkState(NetworkState.Online, Logger);

            await WaitForState(client, ConnectionState.Connecting);
        }
コード例 #3
0
        public async Task WhenInSuspendedStateAfterRetrying_ShouldGoBackToSuspendedState()
        {
            FakeTransportFactory.InitialiseFakeTransport =
                transport => transport.OnConnectChangeStateToConnected = false;

            // this will keep it in connecting state
            var client = GetClientWithFakeTransport(opts =>
            {
                opts.AutoConnect = true;
                opts.DisconnectedRetryTimeout = TimeSpan.FromMilliseconds(10);
                opts.SuspendedRetryTimeout    = TimeSpan.FromMilliseconds(10);
                opts.RealtimeRequestTimeout   = TimeSpan.FromMilliseconds(100);
            });

            client.ExecuteCommand(SetSuspendedStateCommand.Create(ErrorInfo.ReasonSuspended));

            await client.WaitForState(ConnectionState.Connecting);

            await client.WaitForState(ConnectionState.Suspended);
        }
コード例 #4
0
        public async Task WhenInSuspendedState_ShouldTryAndReconnectAfterSuspendRetryTimeoutIsReached()
        {
            DateTimeOffset Func() => DateTimeOffset.UtcNow;

            FakeTransportFactory.InitialiseFakeTransport =
                transport => transport.OnConnectChangeStateToConnected = false;

            // this will keep it in connecting state
            var client = GetClientWithFakeTransport(opts =>
            {
                opts.AutoConnect = false;
                opts.DisconnectedRetryTimeout = TimeSpan.FromMilliseconds(10);
                opts.SuspendedRetryTimeout    = TimeSpan.FromMilliseconds(1000);
                opts.NowFunc = Func;
            });

            client.ExecuteCommand(SetSuspendedStateCommand.Create(ErrorInfo.ReasonSuspended));

            var elapsed = await client.WaitForState(ConnectionState.Connecting);

            elapsed.Should().BeCloseTo(client.Options.SuspendedRetryTimeout, TimeSpan.FromMilliseconds(1000));
        }