From 2b994fdc0c97b7d4706aca8ee62189de54e44535 Mon Sep 17 00:00:00 2001 From: ta264 Date: Sat, 15 Aug 2020 14:18:51 +0100 Subject: [PATCH] Run integration tests in parallel Revert "Try to fix alpine integration tests" This reverts commit d8cb86c5dd399956457a35b5e349987b646bf029. [common] --- azure-pipelines.yml | 10 +++--- .../IntegrationTest.cs | 17 +++++++--- .../Readarr.Integration.Test.csproj | 5 --- .../integration.runsettings | 11 ------- src/NzbDrone.Test.Common/NzbDroneRunner.cs | 31 ++++++++++++++++--- test.sh | 1 - 6 files changed, 43 insertions(+), 32 deletions(-) delete mode 100644 src/NzbDrone.Integration.Test/integration.runsettings diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5b4f76977..14c279f67 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -484,9 +484,8 @@ stages: cp -r -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}/bin/Readarr/. ./bin/ displayName: Move Package Contents - bash: | - cd ${TESTSFOLDER} - chmod a+x test.sh - ./test.sh ${OSNAME} Integration Test + chmod a+x ${TESTSFOLDER}/test.sh + ${TESTSFOLDER}/test.sh ${OSNAME} Integration Test displayName: Run Integration Tests - task: PublishTestResults@2 inputs: @@ -557,9 +556,8 @@ stages: cp -r -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}/bin/Readarr/. ./bin/ displayName: Move Package Contents - bash: | - cd ${TESTSFOLDER} - chmod a+x test.sh - ./test.sh Linux Integration Test + chmod a+x ${TESTSFOLDER}/test.sh + ${TESTSFOLDER}/test.sh Linux Integration Test displayName: Run Integration Tests - task: PublishTestResults@2 inputs: diff --git a/src/NzbDrone.Integration.Test/IntegrationTest.cs b/src/NzbDrone.Integration.Test/IntegrationTest.cs index 7659b7958..7ccb41f43 100644 --- a/src/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/IntegrationTest.cs @@ -1,24 +1,33 @@ +using System.Threading; using NLog; +using NUnit.Framework; using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Test.Common; using Readarr.Http.ClientSchema; namespace NzbDrone.Integration.Test { + [Parallelizable(ParallelScope.Fixtures)] public abstract class IntegrationTest : IntegrationTestBase { + protected static int StaticPort = 8787; + protected NzbDroneRunner _runner; public override string AuthorRootFolder => GetTempDirectory("AuthorRootFolder"); - protected override string RootUrl => "http://localhost:8787/"; + protected int Port { get; private set; } + + protected override string RootUrl => $"http://localhost:{Port}/"; protected override string ApiKey => _runner.ApiKey; protected override void StartTestTarget() { - _runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger()); - _runner.KillAll(); + Port = Interlocked.Increment(ref StaticPort); + + _runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger(), Port); + _runner.Kill(); _runner.Start(); } @@ -45,7 +54,7 @@ namespace NzbDrone.Integration.Test protected override void StopTestTarget() { - _runner.KillAll(); + _runner.Kill(); } } } diff --git a/src/NzbDrone.Integration.Test/Readarr.Integration.Test.csproj b/src/NzbDrone.Integration.Test/Readarr.Integration.Test.csproj index b3c127d26..2871abd7e 100644 --- a/src/NzbDrone.Integration.Test/Readarr.Integration.Test.csproj +++ b/src/NzbDrone.Integration.Test/Readarr.Integration.Test.csproj @@ -22,9 +22,4 @@ - - - Always - - diff --git a/src/NzbDrone.Integration.Test/integration.runsettings b/src/NzbDrone.Integration.Test/integration.runsettings deleted file mode 100644 index 500abe263..000000000 --- a/src/NzbDrone.Integration.Test/integration.runsettings +++ /dev/null @@ -1,11 +0,0 @@ - - - - 1 - - true - - - 1 - - diff --git a/src/NzbDrone.Test.Common/NzbDroneRunner.cs b/src/NzbDrone.Test.Common/NzbDroneRunner.cs index a27fe0beb..ecb705fb1 100644 --- a/src/NzbDrone.Test.Common/NzbDroneRunner.cs +++ b/src/NzbDrone.Test.Common/NzbDroneRunner.cs @@ -23,11 +23,14 @@ namespace NzbDrone.Test.Common public string AppData { get; private set; } public string ApiKey { get; private set; } + public int Port { get; private set; } public NzbDroneRunner(Logger logger, int port = 8787) { _processProvider = new ProcessProvider(logger); - _restClient = new RestClient("http://localhost:8787/api/v1"); + _restClient = new RestClient($"http://localhost:{port}/api/v1"); + + Port = port; } public void Start() @@ -83,7 +86,7 @@ namespace NzbDrone.Test.Common if (statusCall.ResponseStatus == ResponseStatus.Completed) { _startupLog = null; - TestContext.Progress.WriteLine("Readarr is started. Running Tests"); + TestContext.Progress.WriteLine($"Readarr {Port} is started. Running Tests"); return; } @@ -93,6 +96,23 @@ namespace NzbDrone.Test.Common } } + public void Kill() + { + try + { + if (_nzbDroneProcess != null) + { + _processProvider.Kill(_nzbDroneProcess.Id); + } + } + catch (InvalidOperationException) + { + // May happen if the process closes while being closed + } + + TestBase.DeleteTempFolder(AppData); + } + public void KillAll() { try @@ -115,7 +135,7 @@ namespace NzbDrone.Test.Common private void Start(string outputNzbdroneConsoleExe) { - TestContext.Progress.WriteLine("Starting instance from {0}", outputNzbdroneConsoleExe); + TestContext.Progress.WriteLine("Starting instance from {0} on port {1}", outputNzbdroneConsoleExe, Port); var args = "-nobrowser -data=\"" + AppData + "\""; _nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, null, OnOutputDataReceived, OnOutputDataReceived); @@ -123,7 +143,7 @@ namespace NzbDrone.Test.Common private void OnOutputDataReceived(string data) { - TestContext.Progress.WriteLine(" > " + data); + TestContext.Progress.WriteLine($" [{Port}] > " + data); if (_startupLog != null) { @@ -147,7 +167,8 @@ namespace NzbDrone.Test.Common new XDeclaration("1.0", "utf-8", "yes"), new XElement(ConfigFileProvider.CONFIG_ELEMENT_NAME, new XElement(nameof(ConfigFileProvider.ApiKey), apiKey), - new XElement(nameof(ConfigFileProvider.AnalyticsEnabled), false))); + new XElement(nameof(ConfigFileProvider.AnalyticsEnabled), false), + new XElement(nameof(ConfigFileProvider.Port), Port))); var data = xDoc.ToString(); diff --git a/test.sh b/test.sh index 7b804d997..e38f76817 100755 --- a/test.sh +++ b/test.sh @@ -49,7 +49,6 @@ if [ "$TYPE" = "Unit" ]; then WHERE="$WHERE&Category!=IntegrationTest&Category!=AutomationTest" elif [ "$TYPE" = "Integration" ] || [ "$TYPE" = "int" ] ; then WHERE="$WHERE&Category=IntegrationTest" - VSTEST_PARAMS="$VSTEST_PARAMS --settings:$TEST_DIR/integration.runsettings" elif [ "$TYPE" = "Automation" ] ; then WHERE="$WHERE&Category=AutomationTest" else