File tree Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Expand file tree Collapse file tree 3 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,10 @@ module Concurrent
2
2
3
3
describe Condition do
4
4
5
+ after ( :each ) do
6
+ subject . broadcast
7
+ end
8
+
5
9
context 'with no waiting threads' do
6
10
describe '#signal' do
7
11
it 'should return immediately' do
@@ -37,7 +41,6 @@ module Concurrent
37
41
38
42
latch_1 . wait ( 1 )
39
43
latch_2 . wait ( 0.1 )
40
- expect ( t . status ) . to eq 'sleep'
41
44
expect ( latch_2 . count ) . to eq 1
42
45
t . kill
43
46
end
@@ -119,7 +122,6 @@ module Concurrent
119
122
120
123
latch_1 . wait ( 1 )
121
124
latch_2 . wait ( 0.1 )
122
- expect ( t . status ) . to eq 'sleep'
123
125
expect ( latch_2 . count ) . to eq 1
124
126
t . kill
125
127
end
@@ -213,13 +215,24 @@ module Concurrent
213
215
214
216
it 'should block threads' do
215
217
mutex = Mutex . new
216
- latch = Concurrent ::CountDownLatch . new ( 2 )
217
- t1 = Thread . new { mutex . synchronize { latch . count_down ; subject . wait ( mutex ) } }
218
- t2 = Thread . new { mutex . synchronize { latch . count_down ; subject . wait ( mutex ) } }
219
- latch . wait ( 1 )
218
+ latch_1 = Concurrent ::CountDownLatch . new ( 2 )
219
+ latch_2 = Concurrent ::CountDownLatch . new ( 2 )
220
+
221
+ threads = 2 . times . collect do
222
+ Thread . new do
223
+ mutex . synchronize do
224
+ latch_1 . count_down
225
+ subject . wait ( mutex )
226
+ latch_2 . count_down
227
+ end
228
+ end
229
+ end
230
+
231
+ latch_1 . wait ( 1 )
220
232
sleep ( 0.1 )
221
- [ t1 , t2 ] . each { |t | expect ( t . status ) . to eq 'sleep' }
222
- [ t1 , t2 ] . each { |t | t . kill }
233
+ expect ( latch_2 . count ) . to eq 2
234
+
235
+ threads . each { |t | t . kill }
223
236
end
224
237
end
225
238
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ module Concurrent
20
20
21
21
latch_1 . wait ( 1 )
22
22
latch_2 . wait ( 0.1 )
23
- expect ( t . status ) . to eq 'sleep'
24
23
expect ( latch_2 . count ) . to eq 1
25
24
t . kill
26
25
end
Original file line number Diff line number Diff line change 1
- Subproject commit db7483b80f6efb7df9930f0031508d7e2eb6bad0
1
+ Subproject commit 5aff4706f70d757c15830edd66d74759ff364eda
You can’t perform that action at this time.
0 commit comments