fix(EventHubs): Workaround health API timeout#1624
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughThe changes introduce a workaround for a GitHub issue in the EventHubs container builder by adding a custom wait strategy that delays 5 seconds before performing the existing HTTP health check. A global using directive for System.Threading.Tasks is also added. Changes
Possibly related PRs
Suggested labels
Poem
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Edit: A better version without an artificial delay: testcontainers-dotnet/src/Testcontainers.EventHubs/EventHubsBuilder.cs Lines 171 to 175 in dde205f TC users can work around this by overriding the default wait strategy and adding an artificial delay ( using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
...
_ = new EventHubsBuilder("mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest")
.WithAcceptLicenseAgreement(true)
// Override the default wait strategy.
.WithWaitStrategy(Wait.ForUnixContainer()
.AddCustomWaitStrategy(new WorkaroundGhIssue69())
.UntilHttpRequestIsSucceeded(request =>
request.ForPort(EventHubsBuilder.EventHubsHttpPort).ForPath("/health")))
.Build();
...
private sealed class WorkaroundGhIssue69 : IWaitUntil
{
public async Task<bool> UntilAsync(IContainer container)
{
await Task.Delay(TimeSpan.FromSeconds(5))
.ConfigureAwait(false);
return true;
}
} |
| request.ForPort(EventHubsHttpPort).ForPath("/health"))); | ||
| .WithWaitStrategy(Wait.ForUnixContainer() | ||
| .AddCustomWaitStrategy(new WorkaroundGhIssue69()) | ||
| .UntilHttpRequestIsSucceeded(request => |
There was a problem hiding this comment.
@HofmeisterAn could it be possible to loop on http call with a smaller (configurable) http timeout.
There was a problem hiding this comment.
No, I don't think this is possible without changing the HttpWaitStrategy implementation.
What does this PR do?
Since the EventHubs image is not versioned, we unfortunately ran into an issue with the latest release. It appears that the health API call fails when the HTTP request is sent too early, causing the client to time out.
While we could catch the timeout or cancellation exception and retry once, the default HTTP timeout is 100 seconds, which would make users wait unnecessarily. It would be better for the EventHubs team to address this issue properly.
The same issue also occurs when using the CLI.
You can find more information here: Azure/azure-event-hubs-emulator-installer#69 (comment).
Why is it important?
Unblock our CI.
Related issues
-
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.