Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
Test tweaks and PR feedback.
  • Loading branch information
mitchdenny committed Aug 28, 2024
commit c96909914be230c7400d9ef7c779ea257814bfe3
4 changes: 1 addition & 3 deletions src/Aspire.Hosting/ResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,7 @@ public static IResourceBuilder<T> WaitForCompletion<T>(this IResourceBuilder<T>
{
builder.ApplicationBuilder.Eventing.Subscribe<BeforeResourceStartedEvent>(builder.Resource, async (e, ct) =>
{
// TODO: Decide how we want to interpret inconsistent results from replicas of projects. For now
// if we detect that the project is configured for replicas we will throw an exception.
if (dependency.Resource.Annotations.Any(a => a is ReplicaAnnotation ra && ra.Replicas > 1))
if (dependency.Resource.TryGetLastAnnotation<ReplicaAnnotation>(out var replicaAnnotation) && replicaAnnotation.Replicas > 1)
{
throw new DistributedApplicationException("WaitForCompletion cannot be used with resources that have replicas.");
}
Expand Down
12 changes: 8 additions & 4 deletions tests/Aspire.Hosting.Tests/WaitForTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public async Task EnsureDependentResourceMovesIntoWaitingState()
// into a Running state, so rather than awaiting it we'll hold onto the
// task so we can inspect the state of the Redis resource which should
// be in a waiting state if everything is working correctly.
var startTask = app.StartAsync();
var startupCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var startTask = app.StartAsync(startupCts.Token);

// We don't want to wait forever for Redis to move into a waiting state,
// it should be super quick, but we'll allow 60 seconds just in case the
Expand Down Expand Up @@ -66,7 +67,8 @@ public async Task EnsureDependentResourceMovesIntoWaitingStateUntilDependencyMov
// into a Finished state, so rather than awaiting it we'll hold onto the
// task so we can inspect the state of the Redis resource which should
// be in a waiting state if everything is working correctly.
var startTask = app.StartAsync();
var startupCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var startTask = app.StartAsync(startupCts.Token);

// We don't want to wait forever for Redis to move into a waiting state,
// it should be super quick, but we'll allow 60 seconds just in case the
Expand Down Expand Up @@ -113,7 +115,8 @@ public async Task EnsureDependencyResourceThatReturnsNonMatchingExitCodeResultsI
// into a Finished state, so rather than awaiting it we'll hold onto the
// task so we can inspect the state of the Redis resource which should
// be in a waiting state if everything is working correctly.
var startTask = app.StartAsync();
var startupCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var startTask = app.StartAsync(startupCts.Token);

// We don't want to wait forever for Redis to move into a waiting state,
// it should be super quick, but we'll allow 60 seconds just in case the
Expand Down Expand Up @@ -161,7 +164,8 @@ public async Task DependencyWithGreaterThan1ReplicaAnnotationCausesDependentReso
// into a Finished state, so rather than awaiting it we'll hold onto the
// task so we can inspect the state of the Redis resource which should
// be in a waiting state if everything is working correctly.
var startTask = app.StartAsync();
var startupCts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
var startTask = app.StartAsync(startupCts.Token);

// We don't want to wait forever for Redis to move into a waiting state,
// it should be super quick, but we'll allow 60 seconds just in case the
Expand Down
Loading