Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure host is in a running state before running tests further #1534

Merged
merged 7 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion osu.Framework/Testing/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using OpenTK;
using OpenTK.Graphics;
using System.Threading.Tasks;
using System.Threading;

namespace osu.Framework.Testing
{
Expand Down Expand Up @@ -46,6 +47,11 @@ public void SetupGameHost()
throw new InvalidCastException($"The test runner must be a {nameof(Game)}.");

runTask = Task.Factory.StartNew(() => host.Run(game), TaskCreationOptions.LongRunning);
while (!game.IsLoaded)
{
checkForErrors();
Thread.Sleep(10);
}
}

[OneTimeTearDown]
Expand Down Expand Up @@ -77,7 +83,18 @@ public void SetupTest()
}

[TearDown]
public void RunTests() => runner.RunTestBlocking(this);
public void RunTests()
{
checkForErrors();
runner.RunTestBlocking(this);
checkForErrors();
}

private void checkForErrors()
{
if (runTask.Exception != null)
throw runTask.Exception;
}

/// <summary>
/// Most derived usages of this start with TestCase. This will be removed for display purposes.
Expand Down
13 changes: 10 additions & 3 deletions osu.Framework/Testing/TestCaseTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Diagnostics;
using System.Threading;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
Expand Down Expand Up @@ -46,7 +47,7 @@ private void load(GameHost host, FrameworkConfigManager config)

protected override void Dispose(bool isDisposing)
{
volume.Value = volumeAtStartup;
if (volume != null) volume.Value = volumeAtStartup;
base.Dispose(isDisposing);
}

Expand All @@ -65,7 +66,10 @@ protected override void LoadComplete()
/// <param name="test">The <see cref="TestCase"/> to run.</param>
public void RunTestBlocking(TestCase test)
{
Trace.Assert(host != null, $"Ensure this runner has been loaded before calling {nameof(RunTestBlocking)}");

bool completed = false;
Exception exception = null;

void complete()
{
Expand All @@ -90,13 +94,16 @@ void complete()
Scheduler.AddDelayed(complete, time_between_tests);
}, e =>
{
exception = e;

This comment was marked as off-topic.

complete();
throw new Exception("The test case threw an exception while running", e);
});
});

while (!completed && host?.ExecutionState != ExecutionState.Stopped)
while (!completed && host.ExecutionState == ExecutionState.Running)

This comment was marked as off-topic.

This comment was marked as off-topic.

Thread.Sleep(10);

if (exception != null)
throw exception;
}
}
}
Expand Down