Issue with SignalR on owin self host

0

I have an implementation of a signalR hub and i have written a bunch of integration tests where in each test i create an instance of the signalR hub hosted on OWIN, and test the hub. Every test works fine if is run as a stand alone test. If i run all the tests together only the first one works and the remaining ones fail. I have put a simple example to demonstrate the issue:

Nuget Packages Used:

Microsoft.AspNet.SignalR.Client version="2.3.0"

Microsoft.AspNet.SignalR.Core version="2.3.0"

Microsoft.Owin version="4.0.0"

Microsoft.Owin.Host.HttpListener version="4.0.0"

Microsoft.Owin.Hosting version="4.0.0"

Microsoft.Owin.Security version="4.0.0"

Newtonsoft.Json version="11.0.2"

Test Code

class Program
{
    static void Main(string[] args)
    {
        string baseAddress = "http://localhost:8088/";

        using (WebApp.Start<Startup>(baseAddress))
        {
            var connection = new HubConnection(baseAddress);
            IHubProxy hub = connection.CreateHubProxy("TestHub");
            connection.Start().Wait();
        }

        using (WebApp.Start<Startup>(baseAddress))
        {
            var connection = new HubConnection(baseAddress);
            IHubProxy hub = connection.CreateHubProxy("TestHub");
            connection.Start().Wait();
        }
    }

    public class TestHub : Hub
    {
        public TestHub() { }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }
}

Expected behavior

Running the code above i would expect to create the SignalR server, the client to connect, dispose the signalr server, create for second time the signalR server, the client to connect and dispose the signalr server.

Actual behavior - Throws the following exception

System.AggregateException
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at SignalRTests.Program.Main(String[] args) in C:\Projects\SignalRTests\SignalRTests\Program.cs:line 25
Inner Exception 1:
TimeoutException: Transport timed out trying to connect
signalr
signalr-hub
signalr.client
asked on Stack Overflow Jul 11, 2018 by Michalis

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0