File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -23,8 +23,16 @@ def run() super(); sleep; end
23
23
24
24
let ( :stopper_class ) do
25
25
Class . new ( worker_class ) {
26
- def initialize ( sleep_time = 0.2 ) @sleep_time = sleep_time ; end ;
27
- def run ( ) super ( ) ; sleep ( @sleep_time ) ; end
26
+ attr_reader :latch
27
+ def initialize ( sleep_time = 0.2 )
28
+ @sleep_time = sleep_time
29
+ @latch = Concurrent ::CountDownLatch . new ( 1 )
30
+ end
31
+ def run
32
+ super
33
+ sleep ( @sleep_time )
34
+ @latch . count_down
35
+ end
28
36
}
29
37
end
30
38
@@ -326,13 +334,18 @@ def mock_thread(status = 'run')
326
334
327
335
context '#count' do
328
336
337
+ let ( :stoppers ) { Array . new }
338
+
329
339
let ( :busy_supervisor ) do
330
340
supervisor = Supervisor . new ( monitor_interval : 60 )
331
341
3 . times do
332
342
supervisor . add_worker ( sleeper_class . new )
333
- supervisor . add_worker ( stopper_class . new )
334
343
supervisor . add_worker ( error_class . new )
335
344
supervisor . add_worker ( runner_class . new )
345
+
346
+ stopper = stopper_class . new
347
+ stoppers << stopper
348
+ supervisor . add_worker ( stopper )
336
349
end
337
350
supervisor
338
351
end
@@ -426,7 +439,7 @@ def mock_thread(status = 'run')
426
439
it 'returns the count of all stopped workers as #stopped' do
427
440
busy_supervisor . count . stopped . should eq total_count
428
441
busy_supervisor . run!
429
- sleep ( 0.5 )
442
+ stoppers . each { | stopper | stopper . latch . wait ( 1 ) }
430
443
431
444
busy_supervisor . count . stopped . should eq stopped_count
432
445
end
You can’t perform that action at this time.
0 commit comments