1
+ require "connection_pool"
1
2
require "feature_store_spec_base"
2
3
require "json"
3
4
require "redis"
@@ -27,11 +28,11 @@ def clear_all_data
27
28
28
29
describe LaunchDarkly ::RedisFeatureStore do
29
30
subject { LaunchDarkly ::RedisFeatureStore }
30
-
31
+
31
32
break if ENV [ 'LD_SKIP_DATABASE_TESTS' ] == '1'
32
33
33
34
# These tests will all fail if there isn't a Redis instance running on the default port.
34
-
35
+
35
36
context "real Redis with local cache" do
36
37
include_examples "feature_store" , method ( :create_redis_store ) , method ( :clear_all_data )
37
38
end
@@ -59,7 +60,7 @@ def make_concurrent_modifier_test_hook(other_client, flag, start_version, end_ve
59
60
flag = { key : "foo" , version : 1 }
60
61
test_hook = make_concurrent_modifier_test_hook ( other_client , flag , 2 , 4 )
61
62
store = create_redis_store ( { test_hook : test_hook } )
62
-
63
+
63
64
begin
64
65
store . init ( LaunchDarkly ::FEATURES => { flag [ :key ] => flag } )
65
66
@@ -77,7 +78,7 @@ def make_concurrent_modifier_test_hook(other_client, flag, start_version, end_ve
77
78
flag = { key : "foo" , version : 1 }
78
79
test_hook = make_concurrent_modifier_test_hook ( other_client , flag , 3 , 3 )
79
80
store = create_redis_store ( { test_hook : test_hook } )
80
-
81
+
81
82
begin
82
83
store . init ( LaunchDarkly ::FEATURES => { flag [ :key ] => flag } )
83
84
@@ -89,4 +90,32 @@ def make_concurrent_modifier_test_hook(other_client, flag, start_version, end_ve
89
90
other_client . close
90
91
end
91
92
end
93
+
94
+ it "shuts down a custom Redis pool by default" do
95
+ unowned_pool = ConnectionPool . new ( size : 1 , timeout : 1 ) { Redis . new ( { url : "redis://localhost:6379" } ) }
96
+ store = create_redis_store ( { pool : unowned_pool } )
97
+
98
+ begin
99
+ store . init ( LaunchDarkly ::FEATURES => { } )
100
+ store . stop
101
+
102
+ expect { unowned_pool . with { } } . to raise_error ( ConnectionPool ::PoolShuttingDownError )
103
+ ensure
104
+ unowned_pool . shutdown { |conn | conn . close }
105
+ end
106
+ end
107
+
108
+ it "doesn't shut down a custom Redis pool if pool_shutdown_on_close = false" do
109
+ unowned_pool = ConnectionPool . new ( size : 1 , timeout : 1 ) { Redis . new ( { url : "redis://localhost:6379" } ) }
110
+ store = create_redis_store ( { pool : unowned_pool , pool_shutdown_on_close : false } )
111
+
112
+ begin
113
+ store . init ( LaunchDarkly ::FEATURES => { } )
114
+ store . stop
115
+
116
+ expect { unowned_pool . with { } } . not_to raise_error ( ConnectionPool ::PoolShuttingDownError )
117
+ ensure
118
+ unowned_pool . shutdown { |conn | conn . close }
119
+ end
120
+ end
92
121
end
0 commit comments