diff --git a/src/ServiceControl.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs b/src/ServiceControl.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs index 2d13b8fbec..b78c31a0da 100644 --- a/src/ServiceControl.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs +++ b/src/ServiceControl.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs @@ -158,15 +158,22 @@ async Task InitializeServiceControlCore(ScenarioContext context) public override async Task Stop(CancellationToken cancellationToken = default) { + // The scenario passes the test's own token here, which has already fired when the test timed out. + // Stopping with it aborts the host mid-shutdown, and the exception that produces replaces the + // timeout as the reported failure. Shutdown gets its own budget instead. + using var shutdown = new CancellationTokenSource(ShutdownTimeout); + using (new DiagnosticTimer($"Test TearDown for {instanceName}")) { - await host.StopAsync(cancellationToken); + await host.StopAsync(shutdown.Token); HttpClient.Dispose(); await host.DisposeAsync(); - await persistenceToUse.Cleanup(cancellationToken); + await persistenceToUse.Cleanup(shutdown.Token); } } + static readonly TimeSpan ShutdownTimeout = TimeSpan.FromSeconds(30); + WebApplication host; readonly ITransportIntegration transportToUse; readonly IAcceptanceTestStorageConfiguration persistenceToUse; diff --git a/src/ServiceControl.Audit.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs b/src/ServiceControl.Audit.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs index 2d873aaa9e..61ba9459cb 100644 --- a/src/ServiceControl.Audit.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs +++ b/src/ServiceControl.Audit.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs @@ -169,14 +169,21 @@ async Task InitializeServiceControlCore(ScenarioContext context) public override async Task Stop(CancellationToken cancellationToken = default) { + // The scenario passes the test's own token here, which has already fired when the test timed out. + // Stopping with it aborts the host mid-shutdown, and the exception that produces replaces the + // timeout as the reported failure. Shutdown gets its own budget instead. + using var shutdown = new CancellationTokenSource(ShutdownTimeout); + using (new DiagnosticTimer($"Test TearDown for {instanceName}")) { - await host.StopAsync(cancellationToken); + await host.StopAsync(shutdown.Token); HttpClient.Dispose(); await host.DisposeAsync(); } } + static readonly TimeSpan ShutdownTimeout = TimeSpan.FromSeconds(30); + string instanceName = Settings.DEFAULT_INSTANCE_NAME; WebApplication host; Settings settings; diff --git a/src/ServiceControl.Monitoring.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs b/src/ServiceControl.Monitoring.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs index 545f2896e5..eaf799522f 100644 --- a/src/ServiceControl.Monitoring.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs +++ b/src/ServiceControl.Monitoring.AcceptanceTests/TestSupport/ServiceControlComponentRunner.cs @@ -135,14 +135,21 @@ async Task InitializeServiceControl(ScenarioContext context, CancellationToken c public override async Task Stop(CancellationToken cancellationToken = default) { + // The scenario passes the test's own token here, which has already fired when the test timed out. + // Stopping with it aborts the host mid-shutdown, and the exception that produces replaces the + // timeout as the reported failure. Shutdown gets its own budget instead. + using var shutdown = new CancellationTokenSource(ShutdownTimeout); + using (new DiagnosticTimer($"Test TearDown for {settings.InstanceName}")) { - await host.StopAsync(cancellationToken); + await host.StopAsync(shutdown.Token); HttpClient.Dispose(); await host.DisposeAsync(); } } + static readonly TimeSpan ShutdownTimeout = TimeSpan.FromSeconds(30); + WebApplication host; Settings settings; }