diff --git a/Wabbajack.BuildServer.Test/ABuildServerSystemTest.cs b/Wabbajack.BuildServer.Test/ABuildServerSystemTest.cs
index 050bce40..b07f9ab2 100644
--- a/Wabbajack.BuildServer.Test/ABuildServerSystemTest.cs
+++ b/Wabbajack.BuildServer.Test/ABuildServerSystemTest.cs
@@ -64,8 +64,40 @@ namespace Wabbajack.BuildServer.Test
_severTempFolder.DisposeAsync().AsTask().Wait();
}
}
+
+ ///
+ /// Bit of a hack to get around that we don't want the system starting and stopping our
+ /// HTTP server for each class its testing.
+ ///
+ ///
+ public class SingletonAdaptor where T : new()
+ {
+ private static T _singleton = default;
+ private static object _lock = new object();
+ public SingletonAdaptor()
+ {
+ }
+
+ public T Deref()
+ {
+ lock (this)
+ {
+ if (_singleton == null)
+ {
+ _singleton = new T();
+ if (_singleton is IAsyncLifetime d)
+ {
+ d.InitializeAsync().Wait();
+ }
+ }
+
+ return _singleton;
+ }
+ }
+ }
- public class ABuildServerSystemTest : XunitContextBase, IClassFixture
+ [Collection("ServerTests")]
+ public class ABuildServerSystemTest : XunitContextBase, IClassFixture>
{
protected readonly Client _client;
private readonly IDisposable _unsubMsgs;
@@ -74,7 +106,7 @@ namespace Wabbajack.BuildServer.Test
protected WorkQueue _queue;
- public ABuildServerSystemTest(ITestOutputHelper output, BuildServerFixture fixture) : base(output)
+ public ABuildServerSystemTest(ITestOutputHelper output, SingletonAdaptor fixture) : base(output)
{
Filters.Clear();
_unsubMsgs = Utils.LogMessages.OfType().Subscribe(onNext: msg => XunitContext.WriteLine(msg.ShortDescription));
@@ -82,9 +114,9 @@ namespace Wabbajack.BuildServer.Test
XunitContext.WriteLine("ERROR: User intervention required: " + msg.ShortDescription));
_client = new Client();
_authedClient = new Client();
- _authedClient.Headers.Add(("x-api-key", fixture.APIKey));
+ Fixture = fixture.Deref();
+ _authedClient.Headers.Add(("x-api-key", Fixture.APIKey));
_queue = new WorkQueue();
- Fixture = fixture;
Queue = new WorkQueue();
}
diff --git a/Wabbajack.BuildServer.Test/BasicServerTests.cs b/Wabbajack.BuildServer.Test/BasicServerTests.cs
index 9a9cf8be..d4cf104b 100644
--- a/Wabbajack.BuildServer.Test/BasicServerTests.cs
+++ b/Wabbajack.BuildServer.Test/BasicServerTests.cs
@@ -6,11 +6,10 @@ using Xunit.Abstractions;
namespace Wabbajack.BuildServer.Test
{
+ [Collection("ServerTests")]
public class BasicServerTests : ABuildServerSystemTest
{
- public BasicServerTests(ITestOutputHelper output, BuildServerFixture fixture) : base(output, fixture)
- {
- }
+
[Fact]
@@ -27,5 +26,8 @@ namespace Wabbajack.BuildServer.Test
Assert.NotEmpty(logs);
}
+ public BasicServerTests(ITestOutputHelper output, SingletonAdaptor fixture) : base(output, fixture)
+ {
+ }
}
}
diff --git a/Wabbajack.BuildServer.Test/IndexedFilesTests.cs b/Wabbajack.BuildServer.Test/IndexedFilesTests.cs
index 19044236..d266f98a 100644
--- a/Wabbajack.BuildServer.Test/IndexedFilesTests.cs
+++ b/Wabbajack.BuildServer.Test/IndexedFilesTests.cs
@@ -14,11 +14,9 @@ using Xunit.Priority;
namespace Wabbajack.BuildServer.Test
{
+ [Collection("ServerTests")]
public class IndexedFilesTests : ABuildServerSystemTest
{
- public IndexedFilesTests(ITestOutputHelper output, BuildServerFixture fixture) : base(output, fixture)
- {
- }
[Fact, Priority(1)]
public async Task CanIngestExportedInis()
@@ -83,5 +81,10 @@ namespace Wabbajack.BuildServer.Test
// File is aleady indexed so nothing gets enqueued
Assert.Null(await SQL.GetJob());
}
+
+ public IndexedFilesTests(ITestOutputHelper output, SingletonAdaptor fixture) : base(output, fixture)
+ {
+
+ }
}
}
diff --git a/Wabbajack.BuildServer.Test/JobQueueTests.cs b/Wabbajack.BuildServer.Test/JobQueueTests.cs
index 2b28583e..4d3125ec 100644
--- a/Wabbajack.BuildServer.Test/JobQueueTests.cs
+++ b/Wabbajack.BuildServer.Test/JobQueueTests.cs
@@ -10,14 +10,17 @@ using Xunit.Abstractions;
namespace Wabbajack.BuildServer.Test
{
- public class BasicTest : ADBTest
+ [Collection("ServerTests")]
+
+ public class BasicTest : ABuildServerSystemTest
{
[Fact]
public async Task CanEneuqueAndGetJobs()
{
var job = new Job {Payload = new GetNexusUpdatesJob()};
- await _sqlService.EnqueueJob(job);
- var found = await _sqlService.GetJob();
+ var sqlService = Fixture.GetService();
+ await sqlService.EnqueueJob(job);
+ var found = await sqlService.GetJob();
Assert.NotNull(found);
Assert.IsAssignableFrom(found.Payload);
}
@@ -25,25 +28,25 @@ namespace Wabbajack.BuildServer.Test
[Fact]
public async Task PriorityMatters()
{
+ var sqlService = Fixture.GetService();
var priority = new List
{
Job.JobPriority.Normal, Job.JobPriority.High, Job.JobPriority.Low
};
foreach (var pri in priority)
- await _sqlService.EnqueueJob(new Job {Payload = new GetNexusUpdatesJob(), Priority = pri});
+ await sqlService.EnqueueJob(new Job {Payload = new GetNexusUpdatesJob(), Priority = pri});
foreach (var pri in priority.OrderByDescending(p => (int)p))
{
- var found = await _sqlService.GetJob();
+ var found = await sqlService.GetJob();
Assert.NotNull(found);
Assert.Equal(pri, found.Priority);
}
}
- public BasicTest()
+
+ public BasicTest(ITestOutputHelper output, SingletonAdaptor fixture) : base(output, fixture)
{
-
-
}
}
}
diff --git a/Wabbajack.BuildServer.Test/UploadedFilesTest.cs b/Wabbajack.BuildServer.Test/UploadedFilesTest.cs
index f71da927..60c73f88 100644
--- a/Wabbajack.BuildServer.Test/UploadedFilesTest.cs
+++ b/Wabbajack.BuildServer.Test/UploadedFilesTest.cs
@@ -12,14 +12,9 @@ using Xunit.Priority;
namespace Wabbajack.BuildServer.Test
{
+ [Collection("ServerTests")]
public class UploadedFilesTest : ABuildServerSystemTest
{
-
- public UploadedFilesTest(ITestOutputHelper helper, BuildServerFixture fixture) : base(helper, fixture)
- {
- }
-
-
[Fact, Priority(1)]
public async Task CanIngestMongoDBExports()
{
@@ -70,5 +65,8 @@ namespace Wabbajack.BuildServer.Test
}
+ public UploadedFilesTest(ITestOutputHelper output, SingletonAdaptor fixture) : base(output, fixture)
+ {
+ }
}
}
diff --git a/Wabbajack.BuildServer.Test/Wabbajack.BuildServer.Test.csproj b/Wabbajack.BuildServer.Test/Wabbajack.BuildServer.Test.csproj
index 8bc4809f..be387e48 100644
--- a/Wabbajack.BuildServer.Test/Wabbajack.BuildServer.Test.csproj
+++ b/Wabbajack.BuildServer.Test/Wabbajack.BuildServer.Test.csproj
@@ -46,6 +46,9 @@
Always
+
+ Always
+
diff --git a/Wabbajack.BuildServer.Test/xunit.runner.json b/Wabbajack.BuildServer.Test/xunit.runner.json
new file mode 100644
index 00000000..2984442e
--- /dev/null
+++ b/Wabbajack.BuildServer.Test/xunit.runner.json
@@ -0,0 +1,4 @@
+{
+ "parallelizeTestCollections": false,
+ "maxParallelThreads": 1
+}
diff --git a/Wabbajack.Test/RestartingDownloadsTests.cs b/Wabbajack.Test/RestartingDownloadsTests.cs
index 4bf43b23..c93e3a6c 100644
--- a/Wabbajack.Test/RestartingDownloadsTests.cs
+++ b/Wabbajack.Test/RestartingDownloadsTests.cs
@@ -53,15 +53,17 @@ namespace Wabbajack.Test
}
}
- public class RestartingDownloadsTests
+ public class RestartingDownloadsTests : IDisposable
{
+ private IDisposable _unsubInfo;
+ private IDisposable _unsubIntevention;
private ITestOutputHelper TestContext { get; set; }
public RestartingDownloadsTests(ITestOutputHelper helper)
{
TestContext = helper;
- Utils.LogMessages.OfType().Subscribe(onNext: msg => TestContext.WriteLine(msg.ShortDescription));
- Utils.LogMessages.OfType().Subscribe(msg =>
+ _unsubInfo = Utils.LogMessages.OfType().Subscribe(onNext: msg => TestContext.WriteLine(msg.ShortDescription));
+ _unsubIntevention = Utils.LogMessages.OfType().Subscribe(msg =>
TestContext.WriteLine("ERROR: User intervention required: " + msg.ShortDescription));
}
@@ -78,6 +80,12 @@ namespace Wabbajack.Test
testFile.Path.Delete();
}
+
+ public void Dispose()
+ {
+ _unsubInfo?.Dispose();
+ _unsubIntevention?.Dispose();
+ }
}