Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class find_handlers_with_the_default_handler_discovery : IntegrationConte
public find_handlers_with_the_default_handler_discovery(DefaultApp @default, ITestOutputHelper output) : base(@default)
{
_output = output;
@default.RecycleIfNecessary();
}

[Fact]
Expand Down
29 changes: 16 additions & 13 deletions src/Testing/CoreTests/IntegrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,7 @@ public DefaultApp()

public void Dispose()
{
Host?.Dispose();
Host = null!;
}

public void RecycleIfNecessary()
{
if (Host == null)
{
Host = WolverineHost.Basic();
}
Host.Dispose();
}

public HandlerChain ChainFor<T>()
Expand All @@ -67,10 +58,13 @@ public class IntegrationContext : IDisposable, IClassFixture<DefaultApp>
{
private readonly DefaultApp _default;

// Only set when a test opts out of the shared fixture via with(). That host belongs to the
// test and has to be disposed with it; the DefaultApp fixture does not, and must not be.
private IHost? _ownedHost;

public IntegrationContext(DefaultApp @default)
{
_default = @default;
_default.RecycleIfNecessary();

Host = _default.Host;
}
Expand All @@ -84,12 +78,21 @@ public IntegrationContext(DefaultApp @default)

public virtual void Dispose()
{
_default.Dispose();
// Dispose only what this test built for itself. DefaultApp is an IClassFixture, so xUnit
// owns its lifetime and disposes it once the class finishes. Tearing it down here — after
// every test method — left the *shared* host disposed for the tests that followed, and the
// guard that papered over that silently rebuilt it as a WolverineHost.Basic() carrying none
// of DefaultApp's handler/service registrations. Tests then passed or failed on ordering.
// See GH-3423.
_ownedHost?.Dispose();
}

protected async Task with(Action<WolverineOptions> configuration)
{
Host = await WolverineHost.ForAsync(configuration);
_ownedHost?.Dispose();

_ownedHost = await WolverineHost.ForAsync(configuration);
Host = _ownedHost;
}

protected HandlerChain chainFor<T>()
Expand Down
Loading