mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
use TestContext.Progress rather than Console.WriteLine for NzbDroneRunner output
This commit is contained in:
parent
687a45c564
commit
e8ce7898c1
@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using NLog;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Processes;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using RestSharp;
|
||||
@ -21,7 +17,7 @@ public class NzbDroneRunner
|
||||
private readonly IProcessProvider _processProvider;
|
||||
private readonly IRestClient _restClient;
|
||||
private Process _nzbDroneProcess;
|
||||
private List<string> _startupLog;
|
||||
private TextWriter _progressWriter;
|
||||
|
||||
public string AppData { get; private set; }
|
||||
public string ApiKey { get; private set; }
|
||||
@ -41,7 +37,8 @@ public void Start()
|
||||
|
||||
var sonarrConsoleExe = OsInfo.IsWindows ? "Sonarr.Console.exe" : "Sonarr.exe";
|
||||
|
||||
_startupLog = new List<string>();
|
||||
_progressWriter = TestContext.Progress;
|
||||
|
||||
if (BuildInfo.IsDebug)
|
||||
{
|
||||
Start(Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "_output", "Sonarr.Console.exe"));
|
||||
@ -57,10 +54,9 @@ public void Start()
|
||||
|
||||
if (_nzbDroneProcess.HasExited)
|
||||
{
|
||||
Console.WriteLine("NzbDrone has exited unexpectedly");
|
||||
_progressWriter.WriteLine("NzbDrone has exited unexpectedly");
|
||||
Thread.Sleep(2000);
|
||||
var output = _startupLog.Join(Environment.NewLine);
|
||||
Assert.Fail("Process has exited: ExitCode={0} Output={1}", _nzbDroneProcess.ExitCode, output);
|
||||
Assert.Fail("Process has exited: ExitCode={0}", _nzbDroneProcess.ExitCode);
|
||||
}
|
||||
|
||||
var request = new RestRequest("system/status");
|
||||
@ -71,12 +67,11 @@ public void Start()
|
||||
|
||||
if (statusCall.ResponseStatus == ResponseStatus.Completed)
|
||||
{
|
||||
_startupLog = null;
|
||||
Console.WriteLine("NzbDrone is started. Running Tests");
|
||||
_progressWriter.WriteLine("NzbDrone is started. Running Tests");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Waiting for NzbDrone to start. Response Status : {0} [{1}] {2}", statusCall.ResponseStatus, statusCall.StatusDescription, statusCall.ErrorException.Message);
|
||||
_progressWriter.WriteLine("Waiting for NzbDrone to start. Response Status : {0} [{1}] {2}", statusCall.ResponseStatus, statusCall.StatusDescription, statusCall.ErrorException.Message);
|
||||
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
@ -105,7 +100,7 @@ public void KillAll()
|
||||
|
||||
private void Start(string outputNzbdroneConsoleExe)
|
||||
{
|
||||
Console.WriteLine("Starting instance from {0}", outputNzbdroneConsoleExe);
|
||||
_progressWriter.WriteLine("Starting instance from {0}", outputNzbdroneConsoleExe);
|
||||
|
||||
var args = "-nobrowser -data=\"" + AppData + "\"";
|
||||
_nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, null, OnOutputDataReceived, OnOutputDataReceived);
|
||||
@ -114,12 +109,7 @@ private void Start(string outputNzbdroneConsoleExe)
|
||||
|
||||
private void OnOutputDataReceived(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
|
||||
if (_startupLog != null)
|
||||
{
|
||||
_startupLog.Add(data);
|
||||
}
|
||||
_progressWriter.WriteLine(" : " + data);
|
||||
|
||||
if (data.Contains("Press enter to exit"))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user