|
@@ -21,6 +21,7 @@ public class GuiTestContext : IDisposable
|
|
private readonly StringBuilder _logsSb;
|
|
private readonly StringBuilder _logsSb;
|
|
private readonly V2TestDriver _driver;
|
|
private readonly V2TestDriver _driver;
|
|
private bool _finished;
|
|
private bool _finished;
|
|
|
|
+ private readonly object _threadLock = new ();
|
|
|
|
|
|
internal GuiTestContext (Func<Toplevel> topLevelBuilder, int width, int height, V2TestDriver driver)
|
|
internal GuiTestContext (Func<Toplevel> topLevelBuilder, int width, int height, V2TestDriver driver)
|
|
{
|
|
{
|
|
@@ -42,46 +43,49 @@ public class GuiTestContext : IDisposable
|
|
|
|
|
|
var booting = new SemaphoreSlim (0, 1);
|
|
var booting = new SemaphoreSlim (0, 1);
|
|
|
|
|
|
- // Start the application in a background thread
|
|
|
|
- _runTask = Task.Run (
|
|
|
|
- () =>
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- ApplicationImpl.ChangeInstance (v2);
|
|
|
|
-
|
|
|
|
- ILogger logger = LoggerFactory.Create (
|
|
|
|
- builder =>
|
|
|
|
- builder.SetMinimumLevel (LogLevel.Trace)
|
|
|
|
- .AddProvider (new TextWriterLoggerProvider (new StringWriter (_logsSb))))
|
|
|
|
- .CreateLogger ("Test Logging");
|
|
|
|
- Logging.Logger = logger;
|
|
|
|
-
|
|
|
|
- v2.Init (null, GetDriverName ());
|
|
|
|
-
|
|
|
|
- booting.Release ();
|
|
|
|
-
|
|
|
|
- Toplevel t = topLevelBuilder ();
|
|
|
|
- t.Closed += (s, e) => { _finished = true; };
|
|
|
|
- Application.Run (t); // This will block, but it's on a background thread now
|
|
|
|
-
|
|
|
|
- t.Dispose ();
|
|
|
|
- Application.Shutdown ();
|
|
|
|
- }
|
|
|
|
- catch (OperationCanceledException)
|
|
|
|
- { }
|
|
|
|
- catch (Exception ex)
|
|
|
|
- {
|
|
|
|
- _ex = ex;
|
|
|
|
- }
|
|
|
|
- finally
|
|
|
|
|
|
+ lock (_threadLock)
|
|
|
|
+ {
|
|
|
|
+ // Start the application in a background thread
|
|
|
|
+ _runTask = Task.Run (
|
|
|
|
+ () =>
|
|
{
|
|
{
|
|
- ApplicationImpl.ChangeInstance (origApp);
|
|
|
|
- Logging.Logger = origLogger;
|
|
|
|
- _finished = true;
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- _cts.Token);
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ApplicationImpl.ChangeInstance (v2);
|
|
|
|
+
|
|
|
|
+ ILogger logger = LoggerFactory.Create (
|
|
|
|
+ builder =>
|
|
|
|
+ builder.SetMinimumLevel (LogLevel.Trace)
|
|
|
|
+ .AddProvider (new TextWriterLoggerProvider (new StringWriter (_logsSb))))
|
|
|
|
+ .CreateLogger ("Test Logging");
|
|
|
|
+ Logging.Logger = logger;
|
|
|
|
+
|
|
|
|
+ v2.Init (null, GetDriverName ());
|
|
|
|
+
|
|
|
|
+ booting.Release ();
|
|
|
|
+
|
|
|
|
+ Toplevel t = topLevelBuilder ();
|
|
|
|
+ t.Closed += (s, e) => { _finished = true; };
|
|
|
|
+ Application.Run (t); // This will block, but it's on a background thread now
|
|
|
|
+
|
|
|
|
+ t.Dispose ();
|
|
|
|
+ Application.Shutdown ();
|
|
|
|
+ }
|
|
|
|
+ catch (OperationCanceledException)
|
|
|
|
+ { }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ _ex = ex;
|
|
|
|
+ }
|
|
|
|
+ finally
|
|
|
|
+ {
|
|
|
|
+ ApplicationImpl.ChangeInstance (origApp);
|
|
|
|
+ Logging.Logger = origLogger;
|
|
|
|
+ _finished = true;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ _cts.Token);
|
|
|
|
+ }
|
|
|
|
|
|
// Wait for booting to complete with a timeout to avoid hangs
|
|
// Wait for booting to complete with a timeout to avoid hangs
|
|
if (!booting.WaitAsync (TimeSpan.FromSeconds (5)).Result)
|
|
if (!booting.WaitAsync (TimeSpan.FromSeconds (5)).Result)
|