test: Use require.Eventually
to fix flaky TestHealthCheck
#483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue(s) does the PR fix:
Fixes #403
Problem
The TestHealthCheck test fails intermittently on CI due to a timing race condition.
The test's final assertion expects the stream's health check endpoint to return
Stream terminated\n
immediately after callingstrm.StopUnordered()
. However,StopUnordered()
is an asynchronous operation, meaning the final status update may not complete instantly.In CI, the test can assert the status while the stream is in an intermediate state (e.g.,
input not connected\noutput not connected\n
), leading to a failure.Solution
This commit fixes the flakiness by using
require.Eventually
to assert the final state of the health check.Instead of asserting immediately, the test now continuously polls the health check endpoint every 100 milliseconds for up to 5 seconds. This gives the asynchronous shutdown process enough time to complete and for the stream to transition to its final
Stream terminated\n
state.Verification
The test now correctly and consistently passes on my local machine after running it 100 times using a loop to simulate the flaky behavior.
I have also executed the following command before submitting the PR