From 0afb957b3db7526e40b1e053163266fef9fb55de Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Wed, 9 Sep 2026 16:29:01 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Stop=20ServiceControl=20test=20h?= =?UTF-8?q?osts=20with=20their=20own=20budget=20instead=20of=20the=20test'?= =?UTF-8?q?s=20cancelled=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scenario runner stops every component with the test's cancellation token, which has already fired when the test timed out. host.StopAsync then aborts inside ErrorIngestion.EnsureStopped, and that TaskCanceledException replaces the timeout as the reported failure, which is how a slow test shows up in CI as "A task was canceled" with no hint that it ran out of time. Shutdown now runs on a 30 second budget of its own. --- .../TestSupport/ServiceControlComponentRunner.cs | 11 +++++++++-- .../TestSupport/ServiceControlComponentRunner.cs | 9 ++++++++- .../TestSupport/ServiceControlComponentRunner.cs | 9 ++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) 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; }