Skip to content

Commit

Permalink
Functional test to verify transports don't reconnect after fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
halter73 committed Jun 21, 2013
1 parent f493b14 commit 4a60670
Showing 1 changed file with 65 additions and 0 deletions.
@@ -1,16 +1,81 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client;
using Microsoft.AspNet.SignalR.Hosting.Memory;
using Microsoft.AspNet.SignalR.Tests.Common;
using Microsoft.AspNet.SignalR.Tests.Common.Infrastructure;
using Microsoft.Owin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Owin;
using Xunit;
using Xunit.Extensions;

namespace Microsoft.AspNet.SignalR.Tests
{
using AppFunc = Func<IDictionary<string, object>, Task>;

public class ConnectionFacts : HostedTest
{
[Fact]
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.Contains("negotiate") && !request.QueryString.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.MapConnection<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);
}
}
}

[Theory]
[InlineData("1337.0", HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Default)]
[InlineData("1337.0", HostType.Memory, TransportType.ServerSentEvents, MessageBusType.Fake)]
Expand Down

0 comments on commit 4a60670

Please sign in to comment.