-
Notifications
You must be signed in to change notification settings - Fork 694
Description
The KnownResourceStates
class includes members for known resource states including 'Running', 'Exited', etc., and a field TerminalStates
that's contains all known states considered terminal, i.e. once resources move to that state they won't move to any other state.
The TerminalStates
field should include the KnownResourceStates.Hidden
value as we still have some resources that end up in that state, e.g. parameters. If one is writing test code today that waits for all resources to reach the KnownResourceStates.Running
state or any terminal state before continuing, they can't simply rely on the KnownResourceStates.TerminalStates
member to do so, e.g. the following code will never complete if there are any resources that move to the KnownResourceStates.Hidden
state:
public static Task WaitForResources(this DistributedApplication app, IEnumerable<string>? targetStates = null, CancellationToken cancellationToken = default)
{
targetStates ??= [KnownResourceStates.Running, ..KnownResourceStates.TerminalStates];
var applicationModel = app.Services.GetRequiredService<DistributedApplicationModel>();
var resourceNotificationService = app.Services.GetRequiredService<ResourceNotificationService>();
return Task.WhenAll(applicationModel.Resources.Select(r => resourceNotificationService.WaitForResourceAsync(r.Name, targetStates, cancellationToken)));
}