Exemplo n.º 1
0
        //[Fact(Skip = "Disabled IIS Express tests because they fail to initialize")]
        public async Task ABlockedReceivedCallbackWillTriggerAnError()
        {
            using (ITestHost host = CreateHost(HostType.IISExpress))
            {
                host.Initialize();

                using (var connection = CreateConnection(host, "/echo"))
                {
                    var       wh = new ManualResetEventSlim();
                    Exception ex = null;

                    connection.DeadlockErrorTimeout = TimeSpan.FromSeconds(1);
                    connection.Received            += _ => wh.Wait(TimeSpan.FromSeconds(5));
                    connection.Error += error =>
                    {
                        ex = error;
                        wh.Set();
                    };

                    await connection.Start();

                    // Ensure the received callback is actually called
                    await connection.Send("");

                    Assert.True(wh.Wait(TimeSpan.FromSeconds(10)));
                    Assert.IsType <SlowCallbackException>(ex);
                }
            }
        }
Exemplo n.º 2
0
        //[Fact(Skip = "Disabled IIS Express tests because they fail to initialize")]
        public async Task ABlockedReceivedCallbackWillTriggerAnError()
        {
            using (ITestHost host = CreateHost(HostType.IISExpress))
            {
                host.Initialize();

                using (var connection = CreateConnection(host, "/echo"))
                {
                    var wh = new TaskCompletionSource <object>();

                    connection.DeadlockErrorTimeout = TimeSpan.FromSeconds(1);
                    connection.Error += error =>
                    {
                        wh.TrySetResult(error);
                    };

                    await connection.Start();

                    // Ensure the received callback is actually called
                    await connection.Send("");

                    Assert.IsType <SlowCallbackException>(await wh.Task.OrTimeout(TimeSpan.FromSeconds(10)));
                }
            }
        }
Exemplo n.º 3
0
        //[Fact(Skip = "Disabled IIS Express tests because they fail to initialize")]
        public void WebSocketsTransportFailsIfOnConnectedThrows()
        {
            using (ITestHost host = CreateHost(HostType.IISExpress))
            {
                host.Initialize();

                var connection = CreateConnection(host, "/fall-back-throws");

                using (connection)
                {
                    Assert.Throws <AggregateException>(() => connection.Start(new WebSocketTransport()).Wait());
                }
            }
        }
Exemplo n.º 4
0
            public void ConnectionCanBeEstablishedWithPreSendRequestHeadersEventAttached()
            {
                using (ITestHost host = CreateHost(HostType.IISExpress))
                {
                    ((IISExpressTestHost)host).AttachToPreSendRequestHeaders = true;
                    host.Initialize();

                    var connection = CreateConnection(host, "/async-on-connected");

                    using (connection)
                    {
                        Assert.True(connection.Start().Wait(TimeSpan.FromSeconds(10)), "The connection failed to start.");
                    }
                }
            }
Exemplo n.º 5
0
        public void TransportConnectTimeoutDoesNotAddupOverNegotiateRequests()
        {
            using (ITestHost host = CreateHost(HostType.IISExpress))
            {
                host.Initialize();
                var connection = CreateConnection(host, "/signalr");
                connection.TransportConnectTimeout = TimeSpan.FromSeconds(5);

                using (connection)
                {
                    connection.Start().Wait();
                    var totalTransportConnectTimeout = ((Client.IConnection)connection).TotalTransportConnectTimeout;
                    connection.Stop();
                    connection.Start().Wait();
                    Assert.Equal(((Client.IConnection)connection).TotalTransportConnectTimeout, totalTransportConnectTimeout);
                }
            }
        }
Exemplo n.º 6
0
            public void FallbackToLongPollingIIS()
            {
                using (ITestHost host = CreateHost(HostType.IISExpress))
                {
                    // Reduce transportConnectionTimeout to 5 seconds
                    host.Initialize(transportConnectTimeout: 5);

                    var connection = CreateConnection(host, "/fall-back");

                    using (connection)
                    {
                        var tcs = new TaskCompletionSource <object>();

                        connection.StateChanged += change =>
                        {
                            if (change.NewState == ConnectionState.Reconnecting)
                            {
                                tcs.TrySetException(new Exception("The connection should not be reconnecting"));
                            }
                        };

                        var client     = new DefaultHttpClient();
                        var transports = new IClientTransport[]  {
                            new ServerSentEventsTransport(client),
                            new LongPollingTransport(client)
                        };

                        var transport = new AutoTransport(client, transports);

                        connection.Start(transport).Wait();

                        Assert.Equal(connection.Transport.Name, "longPolling");

                        Assert.False(tcs.Task.Wait(TimeSpan.FromSeconds(5)));
                    }
                }
            }