examples: Poll for expected server logs in test #8871
Merged
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.
Fixes: #8046
Problem
The test is flaky due to a race condition in the driver script. Currently, the script waits for the client to exit and immediately validates the server output:
grpc-go/examples/examples_test.sh
Lines 195 to 219 in 49e224f
In the graceful shutdown example, the expected log is written only after the shutdown is complete:
grpc-go/examples/features/gracefulstop/server/main.go
Line 99 in 49e224f
If the test driver validates the server output after the client stream closes but before the server logs the expected message, the test fails.
Fix
This PR updates the test driver to poll for the expected log in the server output, instead of checking it only once. Additionally, the shutdown of the test server is blocked until either the server logs a failure or a success message.
Validation
To reproduce the failure, I added a 1s sleep just before the line
log.Println("Server stopped gracefully.")in the server code. I verified that the test no longer fails with this fix, even with the artificial delay.RELEASE NOTES: N/A