Skip to content

WaitForResourceHealthyAsync should fail fast if Resource does not exist #8147

Open
@afscrome

Description

@afscrome

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If in a test you try to wait on a resource that doesn't exist in a test, it will hang indefinitely until the test times out. (You did remember to include cancellation right 😢)

Expected Behavior

I'd expect this attempt to wait to fail fast if the resource doesn't exist in the model.

Steps To Reproduce

Take the default test from the starter templates, and throw in a await app.ResourceNotifications.WaitForResourceHealthyAsync("DOESNOTEXIST") call, pointing to a resource that doesn't exist

    public async Task GetWebResourceRootReturnsOkStatusCode()
    {
        // Arrange
        var appHost = await DistributedApplicationTestingBuilder.CreateAsync<Projects.aspire91_AppHost>();
        appHost.Services.AddLogging(logging =>
        {
            logging.SetMinimumLevel(LogLevel.Debug);
            // Override the logging filters from the app's configuration
            logging.AddFilter(appHost.Environment.ApplicationName, LogLevel.Debug);
            logging.AddFilter("Aspire.", LogLevel.Debug);
        });
        appHost.Services.ConfigureHttpClientDefaults(clientBuilder =>
        {
            clientBuilder.AddStandardResilienceHandler();
        });

        await using var app = await appHost.BuildAsync().WaitAsync(DefaultTimeout);
        await app.StartAsync().WaitAsync(DefaultTimeout);

        // Act
        await app.ResourceNotifications.WaitForResourceHealthyAsync("DOESNOTEXIST").WaitAsync(DefaultTimeout);
    }

Exceptions (if any)

Logs:

Aspire.Hosting.DistributedApplication[0]
      Aspire version: 9.1.0+2a8f48ea5811f317a26405eb315aa315cc9e3cea
Aspire.Hosting.DistributedApplication[0]
      Distributed application starting.
Aspire.Hosting.DistributedApplication[0]
      Application host directory is: S:\aspire91\aspire91.AppHost
Aspire.Hosting.DistributedApplication[0]
      Distributed application started. Press Ctrl+C to shut down.
Aspire.Hosting.ApplicationModel.ResourceNotificationService[0]
      Waiting for resource 'DOESNOTEXIST' to enter the 'Healthy' state.

.NET Version info

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-testingIssues pertaining to the APIs in Aspire.Hosting.Testing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions