mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
New: Switch to ASPNetCore Kestrel and SignalR
This commit is contained in:
@@ -15,10 +15,9 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("SignalR on CI seems unstable")]
|
||||
public void should_add_and_delete_root_folders()
|
||||
{
|
||||
ConnectSignalR();
|
||||
ConnectSignalR().Wait();
|
||||
|
||||
var rootFolder = new RootFolderResource
|
||||
{
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using FluentAssertions;
|
||||
using NLog;
|
||||
using Lidarr.Api.V1;
|
||||
using Lidarr.Http;
|
||||
using Lidarr.Http.REST;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using RestSharp;
|
||||
using System.Linq;
|
||||
using Lidarr.Http;
|
||||
|
||||
namespace NzbDrone.Integration.Test.Client
|
||||
{
|
||||
@@ -70,7 +69,9 @@ namespace NzbDrone.Integration.Test.Client
|
||||
|
||||
private static void AssertDisableCache(IList<Parameter> headers)
|
||||
{
|
||||
headers.Single(c => c.Name == "Cache-Control").Value.Should().Be("no-cache, no-store, must-revalidate, max-age=0");
|
||||
// cache control header gets reordered on net core
|
||||
((string)headers.Single(c => c.Name == "Cache-Control").Value).Split(',').Select(x => x.Trim())
|
||||
.Should().BeEquivalentTo("no-store, must-revalidate, no-cache, max-age=0".Split(',').Select(x => x.Trim()));
|
||||
headers.Single(c => c.Name == "Pragma").Value.Should().Be("no-cache");
|
||||
headers.Single(c => c.Name == "Expires").Value.Should().Be("0");
|
||||
}
|
||||
|
||||
@@ -4,8 +4,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;
|
||||
@@ -20,7 +18,6 @@ using Lidarr.Api.V1.Artist;
|
||||
using Lidarr.Api.V1.Albums;
|
||||
using Lidarr.Api.V1.Tags;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Integration.Test.Client;
|
||||
using NzbDrone.SignalR;
|
||||
@@ -28,6 +25,8 @@ using NzbDrone.Test.Common.Categories;
|
||||
using RestSharp;
|
||||
using NzbDrone.Core.MediaFiles.TrackImport.Manual;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
|
||||
namespace NzbDrone.Integration.Test
|
||||
{
|
||||
@@ -57,7 +56,8 @@ namespace NzbDrone.Integration.Test
|
||||
public ClientBase<AlbumResource> WantedCutoffUnmet;
|
||||
|
||||
private List<SignalRMessage> _signalRReceived;
|
||||
private Connection _signalrConnection;
|
||||
|
||||
private HubConnection _signalrConnection;
|
||||
|
||||
protected IEnumerable<SignalRMessage> SignalRMessages => _signalRReceived;
|
||||
|
||||
@@ -136,19 +136,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>();
|
||||
@@ -191,33 +184,51 @@ namespace NzbDrone.Integration.Test
|
||||
return path;
|
||||
}
|
||||
|
||||
protected void ConnectSignalR()
|
||||
protected async Task ConnectSignalR()
|
||||
{
|
||||
_signalRReceived = new List<SignalRMessage>();
|
||||
_signalrConnection = new Connection("http://localhost:8686/signalr");
|
||||
_signalrConnection.Start(new LongPollingTransport()).ContinueWith(task =>
|
||||
_signalrConnection = new HubConnectionBuilder()
|
||||
.WithUrl("http://localhost:8686/signalr/messages", options =>
|
||||
{
|
||||
options.AccessTokenProvider = () => Task.FromResult(ApiKey);
|
||||
})
|
||||
.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);
|
||||
await _signalrConnection.StartAsync();
|
||||
connected = true;
|
||||
break;
|
||||
}
|
||||
catch
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<TargetFrameworks>net462</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNet.SignalR.Client" Version="2.4.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lidarr.Api.V1\Lidarr.Api.V1.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user