Skip to content

Commit

Permalink
Dispose of ThreadRental at conclusion of UITheory test
Browse files Browse the repository at this point in the history
Fixes #44 hang at end of test run.
  • Loading branch information
AArnott committed May 16, 2020
1 parent 68790c2 commit 08cf697
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
14 changes: 3 additions & 11 deletions src/Xunit.StaFact/Sdk/UITheoryTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public UITheoryTestCase(UITestCase.SyncContextType synchronizationContextType, I

internal UITestCase.SyncContextType SynchronizationContextType { get; private set; }

internal ThreadRental ThreadRental { get; private set; }

public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
{
this.ThreadRental = await ThreadRental.CreateAsync(UITestCase.GetAdapter(this.SynchronizationContextType), this.TestMethod);
await this.ThreadRental.SynchronizationContext;
return await new UITheoryTestCaseRunner(this, this.DisplayName, this.SkipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource).RunAsync();
using var threadRental = await ThreadRental.CreateAsync(UITestCase.GetAdapter(this.SynchronizationContextType), this.TestMethod);
await threadRental.SynchronizationContext;
return await new UITheoryTestCaseRunner(this, this.DisplayName, this.SkipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource, threadRental).RunAsync();
}

public override void Deserialize(IXunitSerializationInfo data)
Expand All @@ -47,11 +45,5 @@ public override void Serialize(IXunitSerializationInfo data)

data.AddValue("SyncContextType", this.SynchronizationContextType.ToString());
}

public override void Dispose()
{
this.ThreadRental?.Dispose();
base.Dispose();
}
}
}
7 changes: 5 additions & 2 deletions src/Xunit.StaFact/Sdk/UITheoryTestCaseRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ namespace Xunit.Sdk

public class UITheoryTestCaseRunner : XunitTheoryTestCaseRunner
{
public UITheoryTestCaseRunner(UITheoryTestCase testCase, string displayName, string skipReason, object[] constructorArguments, IMessageSink diagnosticMessageSink, IMessageBus messageBus, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
private readonly ThreadRental threadRental;

internal UITheoryTestCaseRunner(UITheoryTestCase testCase, string displayName, string skipReason, object[] constructorArguments, IMessageSink diagnosticMessageSink, IMessageBus messageBus, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource, ThreadRental threadRental)
: base(testCase, displayName, skipReason, constructorArguments, diagnosticMessageSink, messageBus, aggregator, cancellationTokenSource)
{
this.threadRental = threadRental;
}

internal new UITheoryTestCase TestCase => (UITheoryTestCase)base.TestCase;

protected override XunitTestRunner CreateTestRunner(ITest test, IMessageBus messageBus, Type testClass, object[] constructorArguments, MethodInfo testMethod, object[] testMethodArguments, string skipReason, IReadOnlyList<BeforeAfterTestAttribute> beforeAfterAttributes, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
=> new UITestRunner(test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, cancellationTokenSource, this.TestCase.ThreadRental);
=> new UITestRunner(test, messageBus, testClass, constructorArguments, testMethod, testMethodArguments, skipReason, beforeAfterAttributes, aggregator, cancellationTokenSource, this.threadRental);
}
}

0 comments on commit 08cf697

Please sign in to comment.