-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
grpc: Fix flaky picker_wrapper tests #7560
Conversation
4ad4c80
to
7af8c3c
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7560 +/- ##
==========================================
- Coverage 82.07% 81.70% -0.38%
==========================================
Files 360 361 +1
Lines 27533 27816 +283
==========================================
+ Hits 22599 22726 +127
- Misses 3759 3876 +117
- Partials 1175 1214 +39 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find. LGTM modulo the minor nit.
picker_wrapper_test.go
Outdated
@@ -80,19 +81,24 @@ func (s) TestBlockingPick(t *testing.T) { | |||
var finishedCount uint64 | |||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | |||
defer cancel() | |||
wg := sync.WaitGroup{} | |||
wg.Add(goroutineCount) | |||
for i := goroutineCount; i > 0; i-- { | |||
go func() { | |||
if tr, _, err := bp.pick(ctx, true, balancer.PickInfo{}); err != nil || tr != testT { | |||
t.Errorf("bp.pick returned non-nil error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: While you are here, could you please improve these error messages to say something like:
t.Errorf("bp.pick returned transport: %v, error: %v, want transport: %v, error: nil", tr, err, testT)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the error messages for the 4 tests.
Fixes: #7521
Background
The tests call picker_wrapper.pick() in 5 go routines. The go routines are blocked on either the context getting cancelled or the picker being updated.
grpc-go/picker_wrapper.go
Lines 120 to 134 in cfd14ba
The context is cancelled through a deferred statement when the test function exits. The test function updates the picker in the last line before exiting:
grpc-go/picker_wrapper_test.go
Line 162 in cfd14ba
When the picker go routines see the context getting cancelled before the picker update, they log an error causing the test to fail.
Repro
Add a
time.Sleep(100 * time.Milliseconds)
just before waiting on the picker update / context cancellation here:grpc-go/picker_wrapper.go
Lines 116 to 120 in cfd14ba
This will cause the test to fail with the following log
picker_wrapper_test.go:153: bp.pick returned non-nil error: rpc error: code = Canceled desc = received context error while waiting for new LB policy update: context canceled
Fix
Wait for all the go routines to finish before returning from the test function and cancelling the context.
RELEASE NOTES: None