Fixed flaky test by flushing logs and getting them via the api
This commit is contained in:
parent
7eeff32185
commit
3fdc50b354
|
@ -1,9 +1,10 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NzbDrone.Common.Disk;
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Responses;
|
using Nancy.Responses;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using Sonarr.Http;
|
using Sonarr.Http;
|
||||||
|
|
||||||
|
@ -54,6 +55,8 @@ namespace NzbDrone.Api.Logs
|
||||||
|
|
||||||
private Response GetLogFileResponse(string filename)
|
private Response GetLogFileResponse(string filename)
|
||||||
{
|
{
|
||||||
|
LogManager.Flush();
|
||||||
|
|
||||||
var filePath = GetLogFilePath(filename);
|
var filePath = GetLogFilePath(filename);
|
||||||
|
|
||||||
if (!_diskProvider.FileExists(filePath))
|
if (!_diskProvider.FileExists(filePath))
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Execute<T>(IRestRequest request, HttpStatusCode statusCode) where T : class, new()
|
public string Execute(IRestRequest request, HttpStatusCode statusCode)
|
||||||
{
|
{
|
||||||
_logger.Info("{0}: {1}", request.Method, _restClient.BuildUri(request));
|
_logger.Info("{0}: {1}", request.Method, _restClient.BuildUri(request));
|
||||||
|
|
||||||
|
@ -58,7 +58,14 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
|
|
||||||
response.StatusCode.Should().Be(statusCode);
|
response.StatusCode.Should().Be(statusCode);
|
||||||
|
|
||||||
return Json.Deserialize<T>(response.Content);
|
return response.Content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Execute<T>(IRestRequest request, HttpStatusCode statusCode) where T : class, new()
|
||||||
|
{
|
||||||
|
var content = Execute(request, statusCode);
|
||||||
|
|
||||||
|
return Json.Deserialize<T>(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AssertDisableCache(IList<Parameter> headers)
|
private static void AssertDisableCache(IList<Parameter> headers)
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
using System;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
namespace NzbDrone.Integration.Test.Client
|
||||||
|
{
|
||||||
|
public class LogsClient : ClientBase
|
||||||
|
{
|
||||||
|
public LogsClient(IRestClient restClient, string apiKey)
|
||||||
|
: base(restClient, apiKey, "log/file")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] GetLogFileLines(string filename)
|
||||||
|
{
|
||||||
|
var request = BuildRequest(filename);
|
||||||
|
var content = Execute(request, System.Net.HttpStatusCode.OK);
|
||||||
|
|
||||||
|
var lines = content.Split('\n');
|
||||||
|
lines = Array.ConvertAll(lines, s => s.TrimEnd('\r'));
|
||||||
|
Array.Resize(ref lines, lines.Length - 1);
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
using System.IO;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
@ -9,7 +9,6 @@ namespace NzbDrone.Integration.Test
|
||||||
public class HttpLogFixture : IntegrationTest
|
public class HttpLogFixture : IntegrationTest
|
||||||
{
|
{
|
||||||
[Test]
|
[Test]
|
||||||
[Retry(5)]
|
|
||||||
public void should_log_on_error()
|
public void should_log_on_error()
|
||||||
{
|
{
|
||||||
var config = HostConfig.Get(1);
|
var config = HostConfig.Get(1);
|
||||||
|
@ -18,16 +17,18 @@ namespace NzbDrone.Integration.Test
|
||||||
|
|
||||||
var resultGet = Series.All();
|
var resultGet = Series.All();
|
||||||
|
|
||||||
var logFile = Path.Combine(_runner.AppData, "logs", "sonarr.trace.txt");
|
var logFile = "sonarr.trace.txt";
|
||||||
var logLines = File.ReadAllLines(logFile);
|
var logLines = Logs.GetLogFileLines(logFile);
|
||||||
|
|
||||||
var resultPost = Series.InvalidPost(new Api.Series.SeriesResource());
|
var resultPost = Series.InvalidPost(new Api.Series.SeriesResource());
|
||||||
|
|
||||||
logLines = File.ReadAllLines(logFile).Skip(logLines.Length).ToArray();
|
// Skip 2 and 1 to ignore the logs endpoint
|
||||||
|
logLines = Logs.GetLogFileLines(logFile).Skip(logLines.Length + 2).ToArray();
|
||||||
|
Array.Resize(ref logLines, logLines.Length - 1);
|
||||||
|
|
||||||
logLines.Should().Contain(v => v.Contains("|Trace|Http|Req"));
|
logLines.Should().Contain(v => v.Contains("|Trace|Http|Req") && v.Contains("/api/series/"));
|
||||||
logLines.Should().Contain(v => v.Contains("|Trace|Http|Res"));
|
logLines.Should().Contain(v => v.Contains("|Trace|Http|Res") && v.Contains("/api/series/: 400.BadRequest"));
|
||||||
logLines.Should().Contain(v => v.Contains("|Debug|Api|"));
|
logLines.Should().Contain(v => v.Contains("|Debug|Api|") && v.Contains("/api/series/: 400.BadRequest"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ namespace NzbDrone.Integration.Test
|
||||||
public ClientBase<HistoryResource> History;
|
public ClientBase<HistoryResource> History;
|
||||||
public ClientBase<HostConfigResource> HostConfig;
|
public ClientBase<HostConfigResource> HostConfig;
|
||||||
public IndexerClient Indexers;
|
public IndexerClient Indexers;
|
||||||
|
public LogsClient Logs;
|
||||||
public ClientBase<NamingConfigResource> NamingConfig;
|
public ClientBase<NamingConfigResource> NamingConfig;
|
||||||
public NotificationClient Notifications;
|
public NotificationClient Notifications;
|
||||||
public ClientBase<ProfileResource> Profiles;
|
public ClientBase<ProfileResource> Profiles;
|
||||||
|
@ -106,6 +107,7 @@ namespace NzbDrone.Integration.Test
|
||||||
History = new ClientBase<HistoryResource>(RestClient, ApiKey);
|
History = new ClientBase<HistoryResource>(RestClient, ApiKey);
|
||||||
HostConfig = new ClientBase<HostConfigResource>(RestClient, ApiKey, "config/host");
|
HostConfig = new ClientBase<HostConfigResource>(RestClient, ApiKey, "config/host");
|
||||||
Indexers = new IndexerClient(RestClient, ApiKey);
|
Indexers = new IndexerClient(RestClient, ApiKey);
|
||||||
|
Logs = new LogsClient(RestClient, ApiKey);
|
||||||
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming");
|
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming");
|
||||||
Notifications = new NotificationClient(RestClient, ApiKey);
|
Notifications = new NotificationClient(RestClient, ApiKey);
|
||||||
Profiles = new ClientBase<ProfileResource>(RestClient, ApiKey);
|
Profiles = new ClientBase<ProfileResource>(RestClient, ApiKey);
|
||||||
|
|
Loading…
Reference in New Issue