@@ -132,6 +132,75 @@ def test_threading_with_transaction
132
132
assert_equal ( WANT , @client . call ( 'GET' , '{key}1' ) )
133
133
end
134
134
135
+ def test_ractor
136
+ skip ( 'Ractor is not available' ) unless Object . const_defined? ( :Ractor , false )
137
+
138
+ ractors = Array . new ( MAX_THREADS ) do |i |
139
+ Ractor . new ( i ) do |i |
140
+ c = ::RedisClient . cluster (
141
+ nodes : TEST_NODE_URIS ,
142
+ fixed_hostname : TEST_FIXED_HOSTNAME ,
143
+ **TEST_GENERIC_OPTIONS
144
+ ) . new_client
145
+ c . call ( 'get' , "key#{ i } " )
146
+ rescue StandardError => e
147
+ e
148
+ ensure
149
+ c &.close
150
+ end
151
+ end
152
+
153
+ ractors . each { |r | assert_equal ( WANT , r . take ) }
154
+ end
155
+
156
+ def test_ractor_with_pipelining
157
+ skip ( 'Ractor is not available' ) unless Object . const_defined? ( :Ractor , false )
158
+
159
+ ractors = Array . new ( MAX_THREADS ) do |i |
160
+ Ractor . new ( i ) do |i |
161
+ c = ::RedisClient . cluster (
162
+ nodes : TEST_NODE_URIS ,
163
+ fixed_hostname : TEST_FIXED_HOSTNAME ,
164
+ **TEST_GENERIC_OPTIONS
165
+ ) . new_client
166
+ c . pipelined do |pi |
167
+ pi . call ( 'get' , "key#{ i } " )
168
+ pi . call ( 'get' , "key#{ i } " )
169
+ end
170
+ rescue StandardError => e
171
+ e
172
+ ensure
173
+ c &.close
174
+ end
175
+ end
176
+
177
+ ractors . each { |r | assert_equal ( [ WANT , WANT ] , r . take ) }
178
+ end
179
+
180
+ def test_ractor_with_transaction
181
+ skip ( 'Ractor is not available' ) unless Object . const_defined? ( :Ractor , false )
182
+
183
+ ractors = Array . new ( MAX_THREADS ) do |i |
184
+ Ractor . new ( i ) do |i |
185
+ c = ::RedisClient . cluster (
186
+ nodes : TEST_NODE_URIS ,
187
+ fixed_hostname : TEST_FIXED_HOSTNAME ,
188
+ **TEST_GENERIC_OPTIONS
189
+ ) . new_client
190
+ c . multi ( watch : [ "key#{ i } " ] ) do |tx |
191
+ tx . call ( 'incr' , "key#{ i } " )
192
+ tx . call ( 'incr' , "key#{ i } " )
193
+ end
194
+ rescue StandardError => e
195
+ e
196
+ ensure
197
+ c &.close
198
+ end
199
+ end
200
+
201
+ ractors . each { |r | assert_equal ( [ 2 , 3 ] , r . take ) }
202
+ end
203
+
135
204
private
136
205
137
206
def new_test_client
0 commit comments