mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Switch to ASPNetCore Kestrel and SignalR
This commit is contained in:
@@ -5,8 +5,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNet.SignalR.Client;
|
||||
using Microsoft.AspNet.SignalR.Client.Transports;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Targets;
|
||||
@@ -30,6 +28,10 @@ using NzbDrone.Integration.Test.Client;
|
||||
using NzbDrone.SignalR;
|
||||
using NzbDrone.Test.Common.Categories;
|
||||
using RestSharp;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
@@ -56,7 +58,8 @@ namespace NzbDrone.Integration.Test
|
||||
public ClientBase<MovieResource> WantedCutoffUnmet;
|
||||
|
||||
private List<SignalRMessage> _signalRReceived;
|
||||
private Connection _signalrConnection;
|
||||
|
||||
private HubConnection _signalrConnection;
|
||||
|
||||
protected IEnumerable<SignalRMessage> SignalRMessages => _signalRReceived;
|
||||
|
||||
@@ -132,19 +135,12 @@ namespace NzbDrone.Integration.Test
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void IntegrationTearDown()
|
||||
public async Task IntegrationTearDown()
|
||||
{
|
||||
if (_signalrConnection != null)
|
||||
{
|
||||
switch (_signalrConnection.State)
|
||||
{
|
||||
case ConnectionState.Connected:
|
||||
case ConnectionState.Connecting:
|
||||
{
|
||||
_signalrConnection.Stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await _signalrConnection.StopAsync();
|
||||
|
||||
_signalrConnection = null;
|
||||
_signalRReceived = new List<SignalRMessage>();
|
||||
@@ -187,33 +183,49 @@ namespace NzbDrone.Integration.Test
|
||||
return path;
|
||||
}
|
||||
|
||||
protected void ConnectSignalR()
|
||||
protected async Task ConnectSignalR()
|
||||
{
|
||||
_signalRReceived = new List<SignalRMessage>();
|
||||
_signalrConnection = new Connection("http://localhost:7878/signalr");
|
||||
_signalrConnection.Start(new LongPollingTransport()).ContinueWith(task =>
|
||||
_signalrConnection = new HubConnectionBuilder().WithUrl("http://localhost:7878/signalr/messages").Build();
|
||||
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
_signalrConnection.Closed += e =>
|
||||
{
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
Assert.Fail("SignalrConnection failed. {0}", task.Exception.GetBaseException());
|
||||
}
|
||||
cts.Cancel();
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
_signalrConnection.On<SignalRMessage>("receiveMessage", (message) =>
|
||||
{
|
||||
_signalRReceived.Add(message);
|
||||
});
|
||||
|
||||
var connected = false;
|
||||
var retryCount = 0;
|
||||
|
||||
while (_signalrConnection.State != ConnectionState.Connected)
|
||||
while (!connected)
|
||||
{
|
||||
if (retryCount > 25)
|
||||
try
|
||||
{
|
||||
Assert.Fail("Couldn't establish signalr connection. State: {0}", _signalrConnection.State);
|
||||
Console.WriteLine("Connecting to signalR");
|
||||
|
||||
await _signalrConnection.StartAsync();
|
||||
connected = true;
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (retryCount > 25)
|
||||
{
|
||||
Assert.Fail("Couldn't establish signalR connection");
|
||||
}
|
||||
}
|
||||
|
||||
retryCount++;
|
||||
Console.WriteLine("Connecting to signalR" + _signalrConnection.State);
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
|
||||
_signalrConnection.Received += json => _signalRReceived.Add(Json.Deserialize<SignalRMessage>(json)); ;
|
||||
}
|
||||
|
||||
public static void WaitForCompletion(Func<bool> predicate, int timeout = 10000, int interval = 500)
|
||||
|
Reference in New Issue
Block a user