Skip to content

Commit aa90003

Browse files
authored
Fix flaky test (dotnet#13328)
- The tests were using WaitForTextAsync("Application started.") without specifying a resource name. When myworker1 (the worker process) started faster than mywebapp1 (the web app) and logged "Application started." first, the wait completed even though mywebapp1 wasn't ready yet. The subsequent HTTP request to mywebapp1 resulted in a 400 Bad Request because the app wasn't listening.
1 parent 2619635 commit aa90003

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

tests/Aspire.Hosting.Testing.Tests/TestingBuilderTests.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ public async Task HttpClientGetTest(bool genericEntryPoint)
181181
await using var app = await builder.BuildAsync();
182182
await app.StartAsync();
183183

184-
// Wait for the application to be ready
185-
await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1));
184+
// Wait for the application to be ready - must specify "mywebapp1" to avoid race condition
185+
// where myworker1 logs "Application started." first
186+
await app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1));
186187

187188
var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts =>
188189
{
@@ -240,8 +241,9 @@ public async Task ArgsPropagateToAppHostConfiguration(bool genericEntryPoint, bo
240241
await using var app = await builder.BuildAsync();
241242
await app.StartAsync();
242243

243-
// Wait for the application to be ready
244-
await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1));
244+
// Wait for the application to be ready - must specify "mywebapp1" to avoid race condition
245+
// where myworker1 logs "Application started." first
246+
await app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1));
245247

246248
var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts =>
247249
{
@@ -278,8 +280,9 @@ public async Task ArgsPropagateToAppHostConfigurationAdHocBuilder(bool directArg
278280
await using var app = await builder.BuildAsync();
279281
await app.StartAsync();
280282

281-
// Wait for the application to be ready
282-
await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1));
283+
// Wait for the application to be ready - must specify "mywebapp1" to avoid race condition
284+
// where myworker1 logs "Application started." first
285+
await app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1));
283286

284287
var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts =>
285288
{
@@ -321,8 +324,9 @@ public async Task CanOverrideLaunchProfileViaArgs(string launchProfileName, bool
321324
await using var app = await builder.BuildAsync();
322325
await app.StartAsync();
323326

324-
// Wait for the application to be ready
325-
await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1));
327+
// Wait for the application to be ready - must specify "mywebapp1" to avoid race condition
328+
// where myworker1 logs "Application started." first
329+
await app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1));
326330

327331
var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts =>
328332
{
@@ -372,8 +376,9 @@ public async Task CanOverrideLaunchProfileViaArgsAdHocBuilder(string launchProfi
372376
await using var app = await builder.BuildAsync();
373377
await app.StartAsync();
374378

375-
// Wait for the application to be ready
376-
await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1));
379+
// Wait for the application to be ready - must specify "mywebapp1" to avoid race condition
380+
// where myworker1 logs "Application started." first
381+
await app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1));
377382

378383
var httpClient = app.CreateHttpClientWithResilience("mywebapp1", null, opts =>
379384
{
@@ -421,8 +426,9 @@ public async Task SelectsFirstLaunchProfile(bool genericEntryPoint)
421426
var profileName = config["DOTNET_LAUNCH_PROFILE"];
422427
Assert.Equal("https", profileName);
423428

424-
// Wait for the application to be ready
425-
await app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1));
429+
// Wait for the application to be ready - must specify "mywebapp1" to avoid race condition
430+
// where myworker1 logs "Application started." first
431+
await app.WaitForTextAsync("Application started.", "mywebapp1").WaitAsync(TimeSpan.FromMinutes(1));
426432

427433
// Explicitly get the HTTPS endpoint - this is only available on the "https" launch profile.
428434
var httpClient = app.CreateHttpClientWithResilience("mywebapp1", "https", opts =>

0 commit comments

Comments
 (0)