44
55class TestConcurrency < TestingWrapper
66 MAX_THREADS = Integer ( ENV . fetch ( 'REDIS_CLIENT_MAX_THREADS' , 5 ) )
7- ATTEMPTS = 200
7+ ATTEMPTS = 1000
88 WANT = '1'
99
1010 def setup
@@ -21,9 +21,13 @@ def test_forking
2121
2222 pids = Array . new ( MAX_THREADS ) do
2323 Process . fork do
24- ATTEMPTS . times { MAX_THREADS . times { |i | @client . call ( 'INCR' , "key#{ i } " ) } }
25- sleep 0.1
26- ATTEMPTS . times { MAX_THREADS . times { |i | @client . call ( 'DECR' , "key#{ i } " ) } }
24+ ATTEMPTS . times { |i | @client . call ( 'INCR' , "key#{ i } " ) }
25+ end
26+ end
27+
28+ pids += Array . new ( MAX_THREADS ) do
29+ Process . fork do
30+ ATTEMPTS . times { |i | @client . call ( 'DECR' , "key#{ i } " ) }
2731 end
2832 end
2933
@@ -40,9 +44,13 @@ def test_forking_with_pipelining
4044
4145 pids = Array . new ( MAX_THREADS ) do
4246 Process . fork do
43- @client . pipelined { |pi | ATTEMPTS . times { MAX_THREADS . times { |i | pi . call ( 'INCR' , "key#{ i } " ) } } }
44- sleep 0.1
45- @client . pipelined { |pi | ATTEMPTS . times { MAX_THREADS . times { |i | pi . call ( 'DECR' , "key#{ i } " ) } } }
47+ @client . pipelined { |pi | ATTEMPTS . times { |i | pi . call ( 'INCR' , "key#{ i } " ) } }
48+ end
49+ end
50+
51+ pids += Array . new ( MAX_THREADS ) do
52+ Process . fork do
53+ @client . pipelined { |pi | ATTEMPTS . times { |i | pi . call ( 'DECR' , "key#{ i } " ) } }
4654 end
4755 end
4856
@@ -63,10 +71,8 @@ def test_forking_with_transaction
6371 Process . fork do
6472 @client . multi ( watch : %w[ {key}1 ] ) do |tx |
6573 ATTEMPTS . times do
66- MAX_THREADS . times do
67- tx . call ( 'INCR' , '{key}1' )
68- tx . call ( 'DECR' , '{key}1' )
69- end
74+ tx . call ( 'INCR' , '{key}1' )
75+ tx . call ( 'DECR' , '{key}1' )
7076 end
7177 end
7278 end
@@ -83,8 +89,16 @@ def test_forking_with_transaction
8389 def test_threading
8490 threads = Array . new ( MAX_THREADS ) do
8591 Thread . new do
86- ATTEMPTS . times { MAX_THREADS . times { |i | @client . call ( 'INCR' , "key#{ i } " ) } }
87- ATTEMPTS . times { MAX_THREADS . times { |i | @client . call ( 'DECR' , "key#{ i } " ) } }
92+ ATTEMPTS . times { |i | @client . call ( 'INCR' , "key#{ i } " ) }
93+ nil
94+ rescue StandardError => e
95+ e
96+ end
97+ end
98+
99+ threads += Array . new ( MAX_THREADS ) do
100+ Thread . new do
101+ ATTEMPTS . times { |i | @client . call ( 'DECR' , "key#{ i } " ) }
88102 nil
89103 rescue StandardError => e
90104 e
@@ -98,8 +112,16 @@ def test_threading
98112 def test_threading_with_pipelining
99113 threads = Array . new ( MAX_THREADS ) do
100114 Thread . new do
101- @client . pipelined { |pi | ATTEMPTS . times { MAX_THREADS . times { |i | pi . call ( 'INCR' , "key#{ i } " ) } } }
102- @client . pipelined { |pi | ATTEMPTS . times { MAX_THREADS . times { |i | pi . call ( 'DECR' , "key#{ i } " ) } } }
115+ @client . pipelined { |pi | ATTEMPTS . times { |i | pi . call ( 'INCR' , "key#{ i } " ) } }
116+ nil
117+ rescue StandardError => e
118+ e
119+ end
120+ end
121+
122+ threads += Array . new ( MAX_THREADS ) do
123+ Thread . new do
124+ @client . pipelined { |pi | ATTEMPTS . times { |i | pi . call ( 'DECR' , "key#{ i } " ) } }
103125 nil
104126 rescue StandardError => e
105127 e
@@ -117,10 +139,8 @@ def test_threading_with_transaction
117139 Thread . new do
118140 @client . multi ( watch : %w[ {key}1 ] ) do |tx |
119141 ATTEMPTS . times do
120- MAX_THREADS . times do
121- tx . call ( 'INCR' , '{key}1' )
122- tx . call ( 'DECR' , '{key}1' )
123- end
142+ tx . call ( 'INCR' , '{key}1' )
143+ tx . call ( 'DECR' , '{key}1' )
124144 end
125145 end
126146 rescue StandardError => e
0 commit comments