Fix build server tests when run all at once

This commit is contained in:
Timothy Baldridge 2020-04-01 05:47:47 -06:00
parent e39f483b81
commit 8e5647c474
8 changed files with 80 additions and 27 deletions

View File

@ -64,8 +64,40 @@ namespace Wabbajack.BuildServer.Test
_severTempFolder.DisposeAsync().AsTask().Wait();
}
}
/// <summary>
/// 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.
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingletonAdaptor<T> 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<BuildServerFixture>
[Collection("ServerTests")]
public class ABuildServerSystemTest : XunitContextBase, IClassFixture<SingletonAdaptor<BuildServerFixture>>
{
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<BuildServerFixture> fixture) : base(output)
{
Filters.Clear();
_unsubMsgs = Utils.LogMessages.OfType<IInfo>().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();
}

View File

@ -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<BuildServerFixture> fixture) : base(output, fixture)
{
}
}
}

View File

@ -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<BuildServerFixture> fixture) : base(output, fixture)
{
}
}
}

View File

@ -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<SqlService>();
await sqlService.EnqueueJob(job);
var found = await sqlService.GetJob();
Assert.NotNull(found);
Assert.IsAssignableFrom<GetNexusUpdatesJob>(found.Payload);
}
@ -25,25 +28,25 @@ namespace Wabbajack.BuildServer.Test
[Fact]
public async Task PriorityMatters()
{
var sqlService = Fixture.GetService<SqlService>();
var priority = new List<Job.JobPriority>
{
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<BuildServerFixture> fixture) : base(output, fixture)
{
}
}
}

View File

@ -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<BuildServerFixture> fixture) : base(output, fixture)
{
}
}
}

View File

@ -46,6 +46,9 @@
<None Update="sql\NotifyStates\00e8bbbf591f61a3_6a5eb07c4b3c03fde38c9223a94a38c9076ef8fc8167f77c875c58db8f2aefd2.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,4 @@
{
"parallelizeTestCollections": false,
"maxParallelThreads": 1
}

View File

@ -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<IInfo>().Subscribe(onNext: msg => TestContext.WriteLine(msg.ShortDescription));
Utils.LogMessages.OfType<IUserIntervention>().Subscribe(msg =>
_unsubInfo = Utils.LogMessages.OfType<IInfo>().Subscribe(onNext: msg => TestContext.WriteLine(msg.ShortDescription));
_unsubIntevention = Utils.LogMessages.OfType<IUserIntervention>().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();
}
}