-
Notifications
You must be signed in to change notification settings - Fork 681
Fix TestBuilderTests flakyness #5216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tests/Aspire.Hosting.Tests/Utils/LoggerNotificationExtensions.cs
Outdated
Show resolved
Hide resolved
tests/Aspire.Hosting.Tests/Utils/LoggerNotificationExtensions.cs
Outdated
Show resolved
Hide resolved
NB: this is very similar to what |
This should fix #4650 . |
.. which should allow re-enabling the corresponding tests in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
await foreach (var resourceEvent in resourceNotificationService.WatchAsync(cancellationToken).ConfigureAwait(false)) | ||
{ | ||
if (resource != null && resourceEvent.Resource != resource) | ||
{ | ||
continue; | ||
} | ||
|
||
var resourceId = resourceEvent.ResourceId; | ||
|
||
if (loggingResourceIds.Add(resourceId)) | ||
{ | ||
// Start watching the logs for this resource ID | ||
logWatchTasks.Add(WatchResourceLogs(tcs, resourceId, logTexts, resourceLoggerService, cancellationToken)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this loop ever stop? Only once the application stops?
@@ -47,6 +48,9 @@ public async Task HttpClientGetTest() | |||
var rns = _app.Services.GetRequiredService<ResourceNotificationService>(); | |||
await rns.WaitForResourceAsync("mywebapp1").WaitAsync(TimeSpan.FromSeconds(60)); | |||
|
|||
// Wait for the application to be ready | |||
await _app.WaitForTextAsync("Application started.").WaitAsync(TimeSpan.FromMinutes(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already await rns.WaitForResourceAsync("mywebapp1")
above. Why is this wait needed?
If the existing code isn't good enough, then i think we might need to change our test template code as well, because the previous code is basically what the template spits out:
aspire/src/Aspire.ProjectTemplates/templates/aspire-xunit/IntegrationTest1.cs
Lines 25 to 32 in 024b48b
// await using var app = await appHost.BuildAsync(); | |
// var resourceNotificationService = app.Services.GetRequiredService<ResourceNotificationService>(); | |
// await app.StartAsync(); | |
// // Act | |
// var httpClient = app.CreateHttpClient("webfrontend"); | |
// await resourceNotificationService.WaitForResourceAsync("webfrontend", KnownResourceStates.Running).WaitAsync(TimeSpan.FromSeconds(30)); | |
// var response = await httpClient.GetAsync("/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume WaitForResourceAsync
doesn't account for when the service can actually serve requests. I dumped the logs for this test and added markers before/after each call:
2024-08-08T18:39:12.3897554Z WaitForResourceAsync - Start
2024-08-08T18:39:13.5023642Z WaitForResourceAsync - Stopped
2024-08-08T18:39:13.5024903Z WaitForTextAsync - Start
2024-08-08T18:39:14.3305581Z WaitForTextAsync - Stopped
So quite some delay between WaitForResourceAsync and the application is ready.
Full logs:
info: Aspire.Hosting.DistributedApplication[0]
Aspire version: 8.1.1-dev
info: Aspire.Hosting.DistributedApplication[0]
Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
Application host directory is: D:\aspire\tests\TestingAppHost1\TestingAppHost1.AppHost
info: Aspire.Hosting.DistributedApplication[0]
Distributed application started. Press Ctrl+C to shut down.
info: Aspire.Hosting.Testing.Tests.TestingFactoryTests[0]
2024-08-08T18:39:12.3897554Z WaitForResourceAsync - Start
info: TestingAppHost1.AppHost.Resources.redis1[0]
1: 2024-08-08T18:39:12.504Z f6a9967856a8e04bcc5bac50d9773fd829b7efc3b0c40501a3bf87a63ae76c01
info: TestingAppHost1.AppHost.Resources.postgres1[0]
1: 2024-08-08T18:39:12.508Z 3340cd55a0075dabf1fa27fecbbac6550efdd35d16e358cc5506da329512e0ec
fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
could not create Endpoint object {"Executable": {"name":"myworker1-76788608-hs44so590k"}, "Reconciliation": 7, "ServiceName": "myworker1-76788608", "Workload": "/myworker1-76788608-hs44so590k", "error": "service-producer annotation is invalid: missing information about the port to expose the service"}
info: TestingAppHost1.AppHost.Resources.myworker1[0]
1: 2024-08-08T11:39:12.7923490 info: Microsoft.Hosting.Lifetime[0]
info: TestingAppHost1.AppHost.Resources.myworker1[0]
2: Application started. Press Ctrl+C to shut down.
info: TestingAppHost1.AppHost.Resources.myworker1[0]
3: 2024-08-08T11:39:12.8009449 info: Microsoft.Hosting.Lifetime[0]
info: TestingAppHost1.AppHost.Resources.myworker1[0]
4: Hosting environment: Production
info: TestingAppHost1.AppHost.Resources.myworker1[0]
5: 2024-08-08T11:39:12.8010763 info: Microsoft.Hosting.Lifetime[0]
info: TestingAppHost1.AppHost.Resources.myworker1[0]
6: Content root path: D:\aspire\artifacts\bin\TestingAppHost1.MyWorker\Debug\net8.0
info: Aspire.Hosting.Testing.Tests.TestingFactoryTests[0]
2024-08-08T18:39:13.5023642Z WaitForResourceAsync - Stopped
info: Aspire.Hosting.Testing.Tests.TestingFactoryTests[0]
2024-08-08T18:39:13.5024903Z WaitForTextAsync - Start
info: TestingAppHost1.AppHost.Resources.redis1[0]
2:
info: TestingAppHost1.AppHost.Resources.redis1[0]
3: 2024-08-08T18:39:13.369Z f6a9967856a8e04bcc5bac50d9773fd829b7efc3b0c40501a3bf87a63ae76c01
info: TestingAppHost1.AppHost.Resources.postgres1[0]
2:
info: TestingAppHost1.AppHost.Resources.postgres1[0]
3: 2024-08-08T18:39:13.392Z 3340cd55a0075dabf1fa27fecbbac6550efdd35d16e358cc5506da329512e0ec
fail: Aspire.Hosting.Dcp.dcpctrl.ExecutableReconciler[0]
could not create Endpoint object {"Executable": {"name":"myworker1-76788608-hs44so590k"}, "Reconciliation": 15, "ServiceName": "myworker1-76788608", "Workload": "/myworker1-76788608-hs44so590k", "error": "service-producer annotation is invalid: missing information about the port to expose the service"}
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
1: 2024-08-08T11:39:13.9218060 info: Microsoft.Hosting.Lifetime[14]
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
2: Now listening on: https://localhost:7097
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
3: 2024-08-08T11:39:13.9288476 info: Microsoft.Hosting.Lifetime[14]
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
4: Now listening on: http://localhost:5150
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
5: 2024-08-08T11:39:13.9892275 info: Microsoft.Hosting.Lifetime[0]
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
6: Application started. Press Ctrl+C to shut down.
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
7: 2024-08-08T11:39:13.9903828 info: Microsoft.Hosting.Lifetime[0]
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
8: Hosting environment: Development
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
9: 2024-08-08T11:39:13.9904583 info: Microsoft.Hosting.Lifetime[0]
info: TestingAppHost1.AppHost.Resources.mywebapp1[0]
10: Content root path: D:\aspire\tests\TestingAppHost1\TestingAppHost1.MyWebApp
info: Aspire.Hosting.Testing.Tests.TestingFactoryTests[0]
2024-08-08T18:39:14.3305581Z WaitForTextAsync - Stopped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is how does the tests in our template work today without this? Do we hve this flakiness issue in them?
Fixes
Fixed the tests on local Linux box. Was failing consistently before.
Microsoft Reviewers: Open in CodeFlow