Skip to content
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

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Changes since v6.0.0

- [#654](https://github.com/oauth2-proxy/oauth2-proxy/pull/654) Close client connections after each redis test (@JoelSpeed)
- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
- [#635](https://github.com/oauth2-proxy/oauth2-proxy/pull/635) Support specifying alternative provider TLS trust source(s) (@k-wall)
Expand Down
36 changes: 32 additions & 4 deletions pkg/sessions/redis/session_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ func TestSessionStore(t *testing.T) {
}

var _ = Describe("Redis SessionStore Tests", func() {
// helper interface to allow us to close client connections
// All non-nil redis clients should implement this
type closer interface {
Close() error
}

var mr *miniredis.Miniredis
var ss sessionsapi.SessionStore

BeforeEach(func() {
var err error
Expand All @@ -41,12 +48,25 @@ var _ = Describe("Redis SessionStore Tests", func() {
mr.Close()
})

JustAfterEach(func() {
// Release any connections immediately after the test ends
if redisStore, ok := ss.(*SessionStore); ok {
if redisStore.Client != nil {
Expect(redisStore.Client.(closer).Close()).To(Succeed())
}
}
})

tests.RunSessionStoreTests(
func(opts *options.SessionOptions, cookieOpts *options.CookieOptions) (sessionsapi.SessionStore, error) {
// Set the connection URL
opts.Type = options.RedisSessionStoreType
opts.Redis.ConnectionURL = "redis://" + mr.Addr()
return NewRedisSessionStore(opts, cookieOpts)

// Capture the session store so that we can close the client
var err error
ss, err = NewRedisSessionStore(opts, cookieOpts)
return ss, err
},
func(d time.Duration) error {
mr.FastForward(d)
Expand All @@ -63,7 +83,7 @@ var _ = Describe("Redis SessionStore Tests", func() {
})

AfterEach(func() {
go ms.Close()
ms.Close()
})

tests.RunSessionStoreTests(
Expand All @@ -74,7 +94,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
opts.Redis.SentinelConnectionURLs = []string{sentinelAddr}
opts.Redis.UseSentinel = true
opts.Redis.SentinelMasterName = ms.MasterInfo().Name
return NewRedisSessionStore(opts, cookieOpts)

// Capture the session store so that we can close the client
var err error
ss, err = NewRedisSessionStore(opts, cookieOpts)
return ss, err
},
func(d time.Duration) error {
mr.FastForward(d)
Expand All @@ -90,7 +114,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
opts.Type = options.RedisSessionStoreType
opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
opts.Redis.UseCluster = true
return NewRedisSessionStore(opts, cookieOpts)

// Capture the session store so that we can close the client
var err error
ss, err = NewRedisSessionStore(opts, cookieOpts)
return ss, err
},
func(d time.Duration) error {
mr.FastForward(d)
Expand Down