git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #654 from oauth2-proxy/redis-test-client-close

Close client connections after each redis test

commit39c01d5930cbf1e32c28908042c833b7573a01c1 authorJoel Speed <Joel.speed@hotmail.co.uk> dateFri 3 Jul 2020, 16:43 (6 years ago) parentb0375e85c8a66b
2 files changed+33−4
CHANGELOG.md+1 pkg/sessions/redis/session_store_test.go+32−4
CHANGELOG.md+1
@@ -8,6 +8,7 @@
88
99## Changes since v6.0.0
1010
11+- [#654](https://github.com/oauth2-proxy/oauth2-proxy/pull/654) Close client connections after each redis test (@JoelSpeed)
1112- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
1213- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
1314- [#635](https://github.com/oauth2-proxy/oauth2-proxy/pull/635) Support specifying alternative provider TLS trust source(s) (@k-wall)
pkg/sessions/redis/session_store_test.go+32−4
@@ -29,7 +29,14 @@ func TestSessionStore(t *testing.T) {
2929}
3030
3131var _ = Describe("Redis SessionStore Tests", func() {
32+ // helper interface to allow us to close client connections
33+ // All non-nil redis clients should implement this
34+ type closer interface {
35+ Close() error
36+ }
37+
3238 var mr *miniredis.Miniredis
39+ var ss sessionsapi.SessionStore
3340
3441 BeforeEach(func() {
3542 var err error
@@ -41,12 +48,25 @@ var _ = Describe("Redis SessionStore Tests", func() {
4148 mr.Close()
4249 })
4350
51+ JustAfterEach(func() {
52+ // Release any connections immediately after the test ends
53+ if redisStore, ok := ss.(*SessionStore); ok {
54+ if redisStore.Client != nil {
55+ Expect(redisStore.Client.(closer).Close()).To(Succeed())
56+ }
57+ }
58+ })
59+
4460 tests.RunSessionStoreTests(
4561 func(opts *options.SessionOptions, cookieOpts *options.CookieOptions) (sessionsapi.SessionStore, error) {
4662 // Set the connection URL
4763 opts.Type = options.RedisSessionStoreType
4864 opts.Redis.ConnectionURL = "redis://" + mr.Addr()
49− return NewRedisSessionStore(opts, cookieOpts)
65+
66+ // Capture the session store so that we can close the client
67+ var err error
68+ ss, err = NewRedisSessionStore(opts, cookieOpts)
69+ return ss, err
5070 },
5171 func(d time.Duration) error {
5272 mr.FastForward(d)
@@ -63,7 +83,7 @@ var _ = Describe("Redis SessionStore Tests", func() {
6383 })
6484
6585 AfterEach(func() {
66− go ms.Close()
86+ ms.Close()
6787 })
6888
6989 tests.RunSessionStoreTests(
@@ -74,7 +94,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
7494 opts.Redis.SentinelConnectionURLs = []string{sentinelAddr}
7595 opts.Redis.UseSentinel = true
7696 opts.Redis.SentinelMasterName = ms.MasterInfo().Name
77− return NewRedisSessionStore(opts, cookieOpts)
97+
98+ // Capture the session store so that we can close the client
99+ var err error
100+ ss, err = NewRedisSessionStore(opts, cookieOpts)
101+ return ss, err
78102 },
79103 func(d time.Duration) error {
80104 mr.FastForward(d)
@@ -90,7 +114,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
90114 opts.Type = options.RedisSessionStoreType
91115 opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
92116 opts.Redis.UseCluster = true
93− return NewRedisSessionStore(opts, cookieOpts)
117+
118+ // Capture the session store so that we can close the client
119+ var err error
120+ ss, err = NewRedisSessionStore(opts, cookieOpts)
121+ return ss, err
94122 },
95123 func(d time.Duration) error {
96124 mr.FastForward(d)