Skip to content

Commit

Permalink
Close client connections after each redis test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelSpeed committed Jul 3, 2020
1 parent 390d479 commit 3d80d5b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
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)

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 {
redisStore.Client.(closer).Close()
}
}
})

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

0 comments on commit 3d80d5b

Please sign in to comment.