Commit b7b1cce
authored
examples: Poll for expected server logs in test (#8871)
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:
https://github.com/grpc/grpc-go/blob/49e224f832c21df2cd3fe833189c8a50244f0eee/examples/examples_test.sh#L195-L219
In the graceful shutdown example, the expected log is written only after
the shutdown is complete:
https://github.com/grpc/grpc-go/blob/49e224f832c21df2cd3fe833189c8a50244f0eee/examples/features/gracefulstop/server/main.go#L99
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/A1 parent 2abe1f0 commit b7b1cce
File tree
2 files changed
+24
-1
lines changed- examples
- features/gracefulstop/server
2 files changed
+24
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
210 | 221 | | |
211 | 222 | | |
212 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
99 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
100 | 111 | | |
101 | 112 | | |
102 | 113 | | |
103 | 114 | | |
104 | 115 | | |
| 116 | + | |
105 | 117 | | |
0 commit comments