Skip to content

Commit ba4d96c

Browse files
authored
Add TestContext.Current.CancellationToken support to IntegrationServicesTests (#12132)
1 parent 4a51e7d commit ba4d96c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tests/Aspire.EndToEnd.Tests/IntegrationServicesTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public IntegrationServicesTests(ITestOutputHelper testOutput, IntegrationService
2424
[InlineData(TestResourceNames.efnpgsql)]
2525
[InlineData(TestResourceNames.redis)]
2626
public Task VerifyComponentWorks(TestResourceNames resourceName)
27-
=> RunTestAsync(async () =>
27+
=> RunTestAsync(async (cancellationToken) =>
2828
{
2929
_integrationServicesFixture.EnsureAppHasResources(resourceName);
3030
try
3131
{
32-
var response = await _integrationServicesFixture.IntegrationServiceA.HttpGetAsync("http", $"/{resourceName}/verify");
33-
var responseContent = await response.Content.ReadAsStringAsync();
32+
var response = await _integrationServicesFixture.IntegrationServiceA.HttpGetAsync("http", $"/{resourceName}/verify", cancellationToken);
33+
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);
3434

3535
Assert.True(response.IsSuccessStatusCode, responseContent);
3636
}
@@ -44,23 +44,24 @@ public Task VerifyComponentWorks(TestResourceNames resourceName)
4444
[Fact]
4545
[Trait("scenario", "basicservices")]
4646
public Task VerifyHealthyOnIntegrationServiceA()
47-
=> RunTestAsync(async () =>
47+
=> RunTestAsync(async (cancellationToken) =>
4848
{
4949
// We wait until timeout for the /health endpoint to return successfully. We assume
5050
// that components wired up into this project have health checks enabled.
51-
await _integrationServicesFixture.IntegrationServiceA.WaitForHealthyStatusAsync("http", _testOutput);
51+
await _integrationServicesFixture.IntegrationServiceA.WaitForHealthyStatusAsync("http", _testOutput, cancellationToken);
5252
});
5353

54-
private async Task RunTestAsync(Func<Task> test)
54+
private async Task RunTestAsync(Func<CancellationToken, Task> test)
5555
{
5656
_integrationServicesFixture.Project.EnsureAppHostRunning();
57+
var cancellationToken = TestContext.Current.CancellationToken;
5758
try
5859
{
59-
await test();
60+
await test(cancellationToken);
6061
}
6162
catch
6263
{
63-
await _integrationServicesFixture.Project.DumpDockerInfoAsync();
64+
await _integrationServicesFixture.Project.DumpDockerInfoAsync(cancellationToken: cancellationToken);
6465
throw;
6566
}
6667
}

tests/Shared/TemplatesTesting/AspireProject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ public async ValueTask DisposeAsync()
442442
await StopAppHostAsync().ConfigureAwait(false);
443443
}
444444

445-
public async Task DumpDockerInfoAsync(ITestOutputHelper? testOutputArg = null)
445+
public async Task DumpDockerInfoAsync(ITestOutputHelper? testOutputArg = null, CancellationToken cancellationToken = default)
446446
{
447447
if (!RequiresDockerAttribute.IsSupported)
448448
{

0 commit comments

Comments
 (0)