-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Close client connections after each redis test #654
Conversation
68faafb
to
dfa5bc9
Compare
pkg/sessions/redis/client.go
Outdated
|
||
// close is only used in tests to ensure that client connections are terminated | ||
// after each test is finished | ||
close() error |
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.
Any advantage to just doing these in the tests themselves directly rather than adding to the interface and implementation just for tests sake?
redisStore.Client.(*client).Close()
And for cluster:
redisStore.Client.(*clusterClient).Close()
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'm happy either way to be honest, it's not uncommon for things like this to be implemented for the tests sake within Go I don't think, but I could just do as you've suggested.
I deliberately set the method to private because it's only for testing so it's not on the public interface
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 just had another look and decided I will change it, added a small closer
interface that can be used in the test, WDYT?
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.
Nice -- this looks super clean. I like it.
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.
Looks good to me. Left one design question -- curious your thoughts on the best design (IE hackier test implementation for cleaner production interface VS methods added to the interface just for use in unit tests)
32e99d1
to
3d80d5b
Compare
// Release any connections immediately after the test ends | ||
if redisStore, ok := ss.(*SessionStore); ok { | ||
if redisStore.Client != nil { | ||
redisStore.Client.(closer).Close() |
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.
Since Close()
can error - I think we should assert that it didn't error.
Otherwise someday some developer will run into the same unclear socket timeout/file descriptor errors that are less clear when we could expose more clearly that the error was here.
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 catch, gimme a second
3d80d5b
to
5c8a66b
Compare
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.
Looks good! Thanks for helping to figure this out.
Description
Make sure we close connections in the redis client after each test
Motivation and Context
Fixes #653
How Has This Been Tested?
docker run --rm -it -v $PWD:/go/src/github.com/oauth2-proxy/oauth2-proxy --workdir /go/src/github.com/oauth2-proxy/oauth2-proxy/pkg/sessions/redis golang:1.14 bash -c "ulimit -n 256 && ulimit -a && go test -v ./..."
Checklist: