xds/xdsclient: Fix flaky test TestLRSClient #7559
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: #7241
Background
The test is sometimes getting a second load report before the client closes the stream. The test is setting the load report interval to 50 ms here:
grpc-go/xds/internal/xdsclient/loadreport_test.go
Lines 106 to 109 in cfd14ba
In the final assertion of the test, the test is checking that the very next request present in the fake server's request channel is the client cancellation:
grpc-go/xds/internal/xdsclient/loadreport_test.go
Lines 136 to 138 in cfd14ba
When the the test takes more than 50 ms b/w sending the first LRS response with the load report interval and this final assertion, another load report can be sent by the client here:
grpc-go/xds/internal/xdsclient/transport/loadreport.go
Lines 136 to 150 in cfd14ba
Repro
To make the test fail with a similar error message (
loadreport_test.go:139: unexpected LRS request: &{ <nil>}, <nil>, want error canceled
) add atime.Sleep(100 * time.Millisecond)
just after receiving the first LRS request on the server here:grpc-go/xds/internal/xdsclient/loadreport_test.go
Lines 113 to 116 in cfd14ba
Fix
This PR keeps reading from
fs2.LRSRequestChan.Receive
until we get an error due to context expiration or see the expected client context cancellation response.RELEASE NOTES: None