Skip to content

Support stopping a running resource from an integration test #2899

@DamianEdwards

Description

@DamianEdwards

It would be useful to be able to stop a running resource in a testing scenario for the purposes of verifying behavior when dependencies aren't running. I imagine this would be a method on DistributedApplication or perhaps a new type that can be resolved from the DI container to allow stopping a resource. DCP already supports stopping resources it started.

e.g.:

[Fact]
public async Task HomePageReturnsOkIfRedisIsUnavailable()
{
    var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Program>();
    await using var app = await appHost.BuildAsync();
    await app.StartAsync();
    var httpClient = app.CreateHttpClient("webfrontend");

    await httpClient.GetStringAsync("/"); // This will retry until the webfrontend has started successfully
    await app.StopResourceAsync("cache"); // Now stop the cache container
    var response = await httpClient.GetAsync("/");

    Assert.Equal(HttpStatus.OK, response.StatusCode);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplicationarea-app-testingIssues pertaining to the APIs in Aspire.Hosting.Testing

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions