-
Notifications
You must be signed in to change notification settings - Fork 4.6k
test: Replace WithDialer usages with WithContextDialer #8788
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8788 +/- ##
==========================================
- Coverage 83.48% 83.28% -0.21%
==========================================
Files 414 414
Lines 32720 32723 +3
==========================================
- Hits 27315 27252 -63
- Misses 4025 4069 +44
- Partials 1380 1402 +22
🚀 New features to boost your workflow:
|
debddcb to
e5d0794
Compare
| dl := pl.Dialer() | ||
| conn, err := dl("", time.Duration(0)) | ||
| dl := pl.ContextDialer() | ||
| conn, err := dl(t.Context(), "") |
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.
We do not use t.Context() rather we do something like this :
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
where defaultTestTimeout = 10 * time.Second
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.
Done.
internal/testutils/pipe_listener.go
Outdated
| case <-p.done: | ||
| return nil, errClosed | ||
| case <-ctx.Done(): | ||
| return nil, context.Cause(ctx) |
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.
Can you change this to return ctx.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.
Done.
e5d0794 to
7965ceb
Compare
| opts, scheme := te.configDial() | ||
| dw := &dialerWrapper{} | ||
| // overwrite the dialer before | ||
| opts = append(opts, grpc.WithDialer(dw.dialer)) |
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.
I think we should keep some tests that also check the behaviour of grpc.WithDialer since we say it will be supported throughout 1.x
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.
Hmm, we could add a bool to the test struct, so that tests can select which implementation to use, and then pick some tests to explicitly use the old behavior. However, I'm a bit concerned that this might clash with #8666, which actually prompted me to change the e2e tests to respect the context. Without it, there will probably be test failures, because some goroutines will hang around for 10 secs when closing the connection. But I'd need to verify that, to be sure.
Looking at the implementation of grpc.WithDialer, it simply delegates to grpc.WithContextDialer. Maybe adding a unit test that asserts that WithDialer properly forwards to WithContextDialer might already be sufficient?
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.
Regardless of the decision regarding the e2e tests, I figured a simple unit test would be useful nonetheless, so I added one in 6398f6e.
test/end2end_test.go
Outdated
|
|
||
| func (te *test) withServerTester(fn func(st *serverTester)) { | ||
| c, err := te.e.dialer(te.srvAddr, 10*time.Second) | ||
| ctx, cancel := context.WithTimeout(te.ctx, 10*time.Second) |
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.
please use defaultTestTimeout instead of 10*time.Second
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.
Done.
This will properly pass on cancellation requests, and reduce usage of a deprecated method. Signed-off-by: Tom Wieczorek <[email protected]>
7965ceb to
0471bbf
Compare
After replacing all usages of grpc.WithDialer in the tests, there was no longer any test coverage for it. Since WithContextDialer is used behind the scenes and has proper coverage, we just need to ensure that the timeouts passed to the callback function are derived properly from the connect deadline. Signed-off-by: Tom Wieczorek <[email protected]>
This will properly pass on cancellation requests, and reduce usage of a deprecated method.
See:
RELEASE NOTES: none