git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #654 from oauth2-proxy/redis-test-client-close
39c01d5Joel Speed
CHANGELOG.md+1
@@ -8,6 +8,7 @@
8
8
9## Changes since v6.0.0
9## Changes since v6.0.0
10
10
11+- [#654](https://github.com/oauth2-proxy/oauth2-proxy/pull/654) Close client connections after each redis test (@JoelSpeed)
11- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
12- [#542](https://github.com/oauth2-proxy/oauth2-proxy/pull/542) Move SessionStore tests to independent package (@JoelSpeed)
12- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
13- [#577](https://github.com/oauth2-proxy/oauth2-proxy/pull/577) Move Cipher and Session Store initialisation out of Validation (@JoelSpeed)
13- [#635](https://github.com/oauth2-proxy/oauth2-proxy/pull/635) Support specifying alternative provider TLS trust source(s) (@k-wall)
14- [#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) {
29}
29}
30
30
31var _ = Describe("Redis SessionStore Tests", func() {
31var _ = 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+
32 var mr *miniredis.Miniredis
38 var mr *miniredis.Miniredis
39+ var ss sessionsapi.SessionStore
33
40
34 BeforeEach(func() {
41 BeforeEach(func() {
35 var err error
42 var err error
@@ -41,12 +48,25 @@ var _ = Describe("Redis SessionStore Tests", func() {
41 mr.Close()
48 mr.Close()
42 })
49 })
43
50
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+
44 tests.RunSessionStoreTests(
60 tests.RunSessionStoreTests(
45 func(opts *options.SessionOptions, cookieOpts *options.CookieOptions) (sessionsapi.SessionStore, error) {
61 func(opts *options.SessionOptions, cookieOpts *options.CookieOptions) (sessionsapi.SessionStore, error) {
46 // Set the connection URL
62 // Set the connection URL
47 opts.Type = options.RedisSessionStoreType
63 opts.Type = options.RedisSessionStoreType
48 opts.Redis.ConnectionURL = "redis://" + mr.Addr()
64 opts.Redis.ConnectionURL = "redis://" + mr.Addr()
65+
66+ // Capture the session store so that we can close the client
67+ var err error
49− return NewRedisSessionStore(opts, cookieOpts)
68+ ss, err = NewRedisSessionStore(opts, cookieOpts)
69+ return ss, err
50 },
70 },
51 func(d time.Duration) error {
71 func(d time.Duration) error {
52 mr.FastForward(d)
72 mr.FastForward(d)
@@ -63,7 +83,7 @@ var _ = Describe("Redis SessionStore Tests", func() {
63 })
83 })
64
84
65 AfterEach(func() {
85 AfterEach(func() {
66− go ms.Close()
86+ ms.Close()
67 })
87 })
68
88
69 tests.RunSessionStoreTests(
89 tests.RunSessionStoreTests(
@@ -74,7 +94,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
74 opts.Redis.SentinelConnectionURLs = []string{sentinelAddr}
94 opts.Redis.SentinelConnectionURLs = []string{sentinelAddr}
75 opts.Redis.UseSentinel = true
95 opts.Redis.UseSentinel = true
76 opts.Redis.SentinelMasterName = ms.MasterInfo().Name
96 opts.Redis.SentinelMasterName = ms.MasterInfo().Name
97+
98+ // Capture the session store so that we can close the client
99+ var err error
77− return NewRedisSessionStore(opts, cookieOpts)
100+ ss, err = NewRedisSessionStore(opts, cookieOpts)
101+ return ss, err
78 },
102 },
79 func(d time.Duration) error {
103 func(d time.Duration) error {
80 mr.FastForward(d)
104 mr.FastForward(d)
@@ -90,7 +114,11 @@ var _ = Describe("Redis SessionStore Tests", func() {
90 opts.Type = options.RedisSessionStoreType
114 opts.Type = options.RedisSessionStoreType
91 opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
115 opts.Redis.ClusterConnectionURLs = []string{clusterAddr}
92 opts.Redis.UseCluster = true
116 opts.Redis.UseCluster = true
117+
118+ // Capture the session store so that we can close the client
119+ var err error
93− return NewRedisSessionStore(opts, cookieOpts)
120+ ss, err = NewRedisSessionStore(opts, cookieOpts)
121+ return ss, err
94 },
122 },
95 func(d time.Duration) error {
123 func(d time.Duration) error {
96 mr.FastForward(d)
124 mr.FastForward(d)