示例#1
0
            public void ReconnectDoesntFireAfterTimeOut(TransportType transportType, MessageBusType messageBusType)
            {
                using (var host = new MemoryHost())
                {
                    var conn = new MyReconnect();
                    host.Configure(app =>
                    {
                        var config = new ConnectionConfiguration
                        {
                            Resolver = new DefaultDependencyResolver()
                        };

                        UseMessageBus(messageBusType, config.Resolver);

                        app.MapSignalR <MyReconnect>("/endpoint", config);
                        var configuration = config.Resolver.Resolve <IConfigurationManager>();
                        configuration.DisconnectTimeout = TimeSpan.FromSeconds(6);
                        configuration.ConnectionTimeout = TimeSpan.FromSeconds(2);
                        configuration.KeepAlive         = null;

                        config.Resolver.Register(typeof(MyReconnect), () => conn);
                    });

                    var connection = new Client.Connection("http://foo/endpoint");
                    var transport  = CreateTransport(transportType, host);
                    connection.Start(transport).Wait();

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    connection.Stop();

                    Assert.Equal(0, conn.Reconnects);
                }
            }
示例#2
0
        public void NoReconnectsAfterFallback()
        {
            // There was a regression where the SSE transport would try to reconnect after it times out.
            // This test ensures that no longer happens.
            // #2180
            using (var host = new MemoryHost())
            {
                var myReconnect = new MyReconnect();

                host.Configure(app =>
                {
                    Func <AppFunc, AppFunc> middleware = (next) =>
                    {
                        return(env =>
                        {
                            var request = new OwinRequest(env);
                            var response = new OwinResponse(env);

                            if (!request.Path.Value.Contains("negotiate") && !request.QueryString.Value.Contains("longPolling"))
                            {
                                response.Body = new MemoryStream();
                            }

                            return next(env);
                        });
                    };

                    app.Use(middleware);

                    var config = new ConnectionConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    config.Resolver.Register(typeof(MyReconnect), () => myReconnect);

                    app.MapSignalR <MyReconnect>("/echo", config);
                });

                var connection = new Connection("http://foo/echo");

                using (connection)
                {
                    connection.Start(host).Wait();

                    // Give SSE an opportunity to reconnect
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    Assert.Equal(connection.State, ConnectionState.Connected);
                    Assert.Equal(connection.Transport.Name, "longPolling");
                    Assert.Equal(0, myReconnect.Reconnects);
                }
            }
        }
示例#3
0
        public void ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
        {
            var persistentConnections = new List <MyReconnect>();
            var host = new ServerRestarter(app =>
            {
                var config = new ConnectionConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                UseMessageBus(messageBusType, config.Resolver);

                app.MapSignalR <MyReconnect>("/endpoint", config);

                var conn = new MyReconnect();
                config.Resolver.Register(typeof(MyReconnect), () => conn);
                persistentConnections.Add(conn);
            });

            using (host)
            {
                using (var connection = CreateConnection("http://foo/endpoint"))
                {
                    var transport        = CreateTransport(transportType, host);
                    var pollEvent        = new ManualResetEventSlim();
                    var reconnectedEvent = new ManualResetEventSlim();

                    host.OnPoll = () =>
                    {
                        pollEvent.Set();
                    };

                    connection.Reconnected += () =>
                    {
                        reconnectedEvent.Set();
                    };

                    connection.Start(transport).Wait();

                    // Wait for the /poll before restarting the server
                    Assert.True(pollEvent.Wait(TimeSpan.FromSeconds(15)), "Timed out waiting for poll request");

                    host.Restart();

                    Assert.True(reconnectedEvent.Wait(TimeSpan.FromSeconds(15)), "Timed out waiting for client side reconnect");

                    Assert.Equal(2, persistentConnections.Count);
                    Assert.Equal(1, persistentConnections[1].Reconnects);
                }
            }
        }
示例#4
0
            public void ReconnectFiresAfterHostShutDown()
            {
                using (var host = new MemoryHost())
                {
                    var conn = new MyReconnect();
                    host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
                    host.MapConnection <MyReconnect>("/endpoint");

                    var connection = new Client.Connection("http://foo/endpoint");
                    connection.Start(host).Wait();

                    host.Dispose();

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    Assert.Equal(Client.ConnectionState.Reconnecting, connection.State);

                    connection.Stop();
                }
            }
示例#5
0
            public void ReconnectFiresAfterTimeOutLongPolling()
            {
                using (var host = new MemoryHost())
                {
                    var conn = new MyReconnect();
                    host.Configuration.KeepAlive         = null;
                    host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(5);
                    host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(5);
                    host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
                    host.MapConnection <MyReconnect>("/endpoint");

                    var connection = new Client.Connection("http://foo/endpoint");
                    connection.Start(new Client.Transports.LongPollingTransport(host)).Wait();

                    Thread.Sleep(TimeSpan.FromSeconds(15));

                    connection.Stop();

                    Assert.InRange(conn.Reconnects, 1, 4);
                }
            }
            public void ReconnectFiresAfterTimeOutSSE()
            {
                using (var host = new MemoryHost())
                {
                    var conn = new MyReconnect();
                    host.Configuration.KeepAlive = null;
                    host.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(5);
                    host.Configuration.HeartBeatInterval = TimeSpan.FromSeconds(5);
                    host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
                    host.MapConnection<MyReconnect>("/endpoint");

                    var connection = new Client.Connection("http://foo/endpoint");
                    connection.Start(new Client.Transports.ServerSentEventsTransport(host)).Wait();

                    Thread.Sleep(TimeSpan.FromSeconds(15));

                    connection.Stop();

                    Assert.InRange(conn.Reconnects, 1, 4);
                }
            }
            public void ReconnectFiresAfterHostShutDown()
            {
                using (var host = new MemoryHost())
                {
                    var conn = new MyReconnect();
                    host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
                    host.MapConnection<MyReconnect>("/endpoint");

                    var connection = new Client.Connection("http://foo/endpoint");
                    connection.Start(host).Wait();

                    host.Dispose();

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    Assert.Equal(Client.ConnectionState.Reconnecting, connection.State);

                    connection.Stop();
                }
            }