Run integration tests in parallel

Revert "Try to fix alpine integration tests"

This reverts commit a47854103c
pull/1689/head
ta264 4 years ago committed by Qstick
parent 4d1931fa0e
commit 74f1d804aa

@ -489,9 +489,8 @@ stages:
cp -r -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}/bin/Lidarr/. ./bin/ cp -r -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}/bin/Lidarr/. ./bin/
displayName: Move Package Contents displayName: Move Package Contents
- bash: | - bash: |
cd ${TESTSFOLDER} chmod a+x ${TESTSFOLDER}/test.sh
chmod a+x test.sh ${TESTSFOLDER}/test.sh ${OSNAME} Integration Test
./test.sh ${OSNAME} Integration Test
displayName: Run Integration Tests displayName: Run Integration Tests
- task: PublishTestResults@2 - task: PublishTestResults@2
inputs: inputs:
@ -567,9 +566,8 @@ stages:
cp -r -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}/bin/Lidarr/. ./bin/ cp -r -v ${BUILD_ARTIFACTSTAGINGDIRECTORY}/bin/Lidarr/. ./bin/
displayName: Move Package Contents displayName: Move Package Contents
- bash: | - bash: |
cd ${TESTSFOLDER} chmod a+x ${TESTSFOLDER}/test.sh
chmod a+x test.sh ${TESTSFOLDER}/test.sh Linux Integration Test
./test.sh Linux Integration Test
displayName: Run Integration Tests displayName: Run Integration Tests
- task: PublishTestResults@2 - task: PublishTestResults@2
inputs: inputs:

@ -1,24 +1,33 @@
using System.Threading;
using Lidarr.Http.ClientSchema; using Lidarr.Http.ClientSchema;
using NLog; using NLog;
using NUnit.Framework;
using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Indexers.Newznab;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Integration.Test namespace NzbDrone.Integration.Test
{ {
[Parallelizable(ParallelScope.Fixtures)]
public abstract class IntegrationTest : IntegrationTestBase public abstract class IntegrationTest : IntegrationTestBase
{ {
protected static int StaticPort = 8686;
protected NzbDroneRunner _runner; protected NzbDroneRunner _runner;
public override string ArtistRootFolder => GetTempDirectory("ArtistRootFolder"); public override string ArtistRootFolder => GetTempDirectory("ArtistRootFolder");
protected override string RootUrl => "http://localhost:8686/"; protected int Port { get; private set; }
protected override string RootUrl => $"http://localhost:{Port}/";
protected override string ApiKey => _runner.ApiKey; protected override string ApiKey => _runner.ApiKey;
protected override void StartTestTarget() protected override void StartTestTarget()
{ {
_runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger()); Port = Interlocked.Increment(ref StaticPort);
_runner.KillAll();
_runner = new NzbDroneRunner(LogManager.GetCurrentClassLogger(), Port);
_runner.Kill();
_runner.Start(); _runner.Start();
} }
@ -45,7 +54,7 @@ namespace NzbDrone.Integration.Test
protected override void StopTestTarget() protected override void StopTestTarget()
{ {
_runner.KillAll(); _runner.Kill();
} }
} }
} }

@ -19,9 +19,4 @@
<ProjectReference Include="..\Lidarr.Api.V1\Lidarr.Api.V1.csproj" /> <ProjectReference Include="..\Lidarr.Api.V1\Lidarr.Api.V1.csproj" />
<ProjectReference Include="..\NzbDrone.Test.Common\Lidarr.Test.Common.csproj" /> <ProjectReference Include="..\NzbDrone.Test.Common\Lidarr.Test.Common.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="integration.runsettings">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

@ -1,11 +0,0 @@
<RunSettings>
<RunConfiguration>
<!-- 0 = As many processes as possible, limited by number of cores on machine, 1 = Sequential (1 process), 2-> Given number of processes up to limit by number of cores on machine-->
<MaxCpuCount>1</MaxCpuCount>
<!-- Disables in-assembly parallel execution, applies to both MSTest and NUnit -->
<DisableParallelization>true</DisableParallelization>
</RunConfiguration>
<NUnit>
<NumberOfTestWorkers>1</NumberOfTestWorkers>
</NUnit>
</RunSettings>

@ -23,11 +23,14 @@ namespace NzbDrone.Test.Common
public string AppData { get; private set; } public string AppData { get; private set; }
public string ApiKey { get; private set; } public string ApiKey { get; private set; }
public int Port { get; private set; }
public NzbDroneRunner(Logger logger, int port = 8686) public NzbDroneRunner(Logger logger, int port = 8686)
{ {
_processProvider = new ProcessProvider(logger); _processProvider = new ProcessProvider(logger);
_restClient = new RestClient("http://localhost:8686/api/v1"); _restClient = new RestClient($"http://localhost:{port}/api/v1");
Port = port;
} }
public void Start() public void Start()
@ -83,7 +86,7 @@ namespace NzbDrone.Test.Common
if (statusCall.ResponseStatus == ResponseStatus.Completed) if (statusCall.ResponseStatus == ResponseStatus.Completed)
{ {
_startupLog = null; _startupLog = null;
TestContext.Progress.WriteLine("Lidarr is started. Running Tests"); TestContext.Progress.WriteLine($"Lidarr {Port} is started. Running Tests");
return; 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() public void KillAll()
{ {
try try
@ -115,7 +135,7 @@ namespace NzbDrone.Test.Common
private void Start(string outputNzbdroneConsoleExe) 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 + "\""; var args = "-nobrowser -data=\"" + AppData + "\"";
_nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, null, OnOutputDataReceived, OnOutputDataReceived); _nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, null, OnOutputDataReceived, OnOutputDataReceived);
@ -123,7 +143,7 @@ namespace NzbDrone.Test.Common
private void OnOutputDataReceived(string data) private void OnOutputDataReceived(string data)
{ {
TestContext.Progress.WriteLine(" > " + data); TestContext.Progress.WriteLine($" [{Port}] > " + data);
if (_startupLog != null) if (_startupLog != null)
{ {
@ -147,7 +167,8 @@ namespace NzbDrone.Test.Common
new XDeclaration("1.0", "utf-8", "yes"), new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ConfigFileProvider.CONFIG_ELEMENT_NAME, new XElement(ConfigFileProvider.CONFIG_ELEMENT_NAME,
new XElement(nameof(ConfigFileProvider.ApiKey), apiKey), 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(); var data = xDoc.ToString();

@ -49,7 +49,6 @@ if [ "$TYPE" = "Unit" ]; then
WHERE="$WHERE&Category!=IntegrationTest&Category!=AutomationTest" WHERE="$WHERE&Category!=IntegrationTest&Category!=AutomationTest"
elif [ "$TYPE" = "Integration" ] || [ "$TYPE" = "int" ] ; then elif [ "$TYPE" = "Integration" ] || [ "$TYPE" = "int" ] ; then
WHERE="$WHERE&Category=IntegrationTest" WHERE="$WHERE&Category=IntegrationTest"
VSTEST_PARAMS="$VSTEST_PARAMS --settings:$TEST_DIR/integration.runsettings"
elif [ "$TYPE" = "Automation" ] ; then elif [ "$TYPE" = "Automation" ] ; then
WHERE="$WHERE&Category=AutomationTest" WHERE="$WHERE&Category=AutomationTest"
else else

Loading…
Cancel
Save