コード例 #1
0
        public async Task ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
        {
            var serverRestarts = 0;
            var serverReconnects = 0;

            var host = new ServerRestarter(app =>
            {
                var config = new ConnectionConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                UseMessageBus(messageBusType, config.Resolver);

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

                serverRestarts++;
                serverReconnects = 0;
                config.Resolver.Register(typeof(MyReconnect), () => new MyReconnect(() => serverReconnects++));
            });

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

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

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

                    await connection.Start(transport);

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

                    host.Restart();

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

                    Assert.Equal(2, serverRestarts);
                    Assert.Equal(1, serverReconnects);
                }
            }
        }
コード例 #2
0
        public async Task ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
        {
            var serverRestarts   = 0;
            var serverReconnects = 0;

            var host = new ServerRestarter(app =>
            {
                var config = new ConnectionConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                UseMessageBus(messageBusType, config.Resolver);

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

                serverRestarts++;
                serverReconnects = 0;
                config.Resolver.Register(typeof(MyReconnect), () => new MyReconnect(() => serverReconnects++));
            });

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

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

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

                    await connection.Start(transport);

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

                    host.Restart();

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

                    Assert.Equal(2, serverRestarts);
                    Assert.Equal(1, serverReconnects);
                }
            }
        }
コード例 #3
0
ファイル: ReconnectFacts.cs プロジェクト: Terricide/SignalR-1
        //[InlineData(TransportType.LongPolling, MessageBusType.Fake)]
        //[InlineData(TransportType.LongPolling, MessageBusType.FakeMultiStream)]
        public async Task ReconnectFiresAfterHostShutdown(TransportType transportType, MessageBusType messageBusType)
        {
            var serverStarts     = 0;
            var serverReconnects = 0;

            var host = new ServerRestarter(app =>
            {
                var config = new ConnectionConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                UseMessageBus(messageBusType, config.Resolver);

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

                serverStarts++;
                config.Resolver.Register(typeof(MyReconnect), () => new MyReconnect(() => serverReconnects++));
            });

            using (host)
            {
                using (var connection = CreateConnection("http://foo/endpoint"))
                {
                    var transport        = CreateTransport(transportType, host);
                    var pollEvent        = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
                    var reconnectedEvent = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

                    host.OnPoll = () =>
                    {
                        pollEvent.TrySetResult(null);
                    };

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

                    await connection.Start(transport);

                    // Wait for the /poll before restarting the server
                    await pollEvent.Task.OrTimeout(TimeSpan.FromSeconds(15));

                    host.Restart();

                    await reconnectedEvent.Task.OrTimeout(TimeSpan.FromSeconds(15));

                    Assert.Equal(2, serverStarts);
                    Assert.Equal(1, serverReconnects);
                }
            }
        }
コード例 #4
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);
                }
            }
        }
コード例 #5
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);
                }
            }
        }
コード例 #6
0
ファイル: ReconnectFacts.cs プロジェクト: shihyuyu/SignalR
        public async Task GroupsWorkAfterServerRestart()
        {
            var host = new ServerRestarter(app =>
            {
                var config = new HubConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                app.MapSignalR(config);
            });

            using (host)
            {
                using (var connection = CreateHubConnection("http://foo/"))
                {
                    var reconnectedEvent = new TaskCompletionSource <object>();
                    connection.Reconnected += () => reconnectedEvent.TrySetResult(null);

                    var    hubProxy    = connection.CreateHubProxy("groupChat");
                    var    sendEvent   = new TaskCompletionSource <object>();
                    string sendMessage = null;
                    hubProxy.On <string>("send", message =>
                    {
                        sendMessage = message;
                        sendEvent.TrySetResult(null);
                    });

                    var groupName    = "group$&+,/:;=?@[]1";
                    var groupMessage = "hello";

                    // MemoryHost doesn't support WebSockets, and it is difficult to ensure that
                    // the reconnected event is reliably fired with the LongPollingTransport.
                    await connection.Start(new ServerSentEventsTransport(host));

                    await hubProxy.Invoke("Join", groupName);

                    host.Restart();

                    await reconnectedEvent.Task.OrTimeout(TimeSpan.FromSeconds(15));

                    await hubProxy.Invoke("Send", groupName, groupMessage);

                    await sendEvent.Task.OrTimeout(TimeSpan.FromSeconds(15));

                    Assert.Equal(groupMessage, sendMessage);
                }
            }
        }
コード例 #7
0
        public async Task GroupsWorkAfterServerRestart()
        {
            var host = new ServerRestarter(app =>
            {
                var config = new HubConfiguration
                {
                    Resolver = new DefaultDependencyResolver()
                };

                app.MapSignalR(config);
            });

            using (host)
            {
                using (var connection = CreateHubConnection("http://foo/"))
                {
                    var reconnectedEvent = new AsyncManualResetEvent();
                    connection.Reconnected += reconnectedEvent.Set;

                    var hubProxy = connection.CreateHubProxy("groupChat");
                    var sendEvent = new AsyncManualResetEvent();
                    string sendMessage = null;
                    hubProxy.On<string>("send", message =>
                    {
                        sendMessage = message;
                        sendEvent.Set();
                    });

                    var groupName = "group$&+,/:;=?@[]1";
                    var groupMessage = "hello";

                    // MemoryHost doesn't support WebSockets, and it is difficult to ensure that
                    // the reconnected event is reliably fired with the LongPollingTransport.
                    await connection.Start(new ServerSentEventsTransport(host));

                    await hubProxy.Invoke("Join", groupName);

                    host.Restart();

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

                    await hubProxy.Invoke("Send", groupName, groupMessage);

                    Assert.True(await sendEvent.WaitAsync(TimeSpan.FromSeconds(15)), "Timed out waiting for message.");
                    Assert.Equal(groupMessage, sendMessage);
                }
            }
        }