@@ -4,12 +4,14 @@ module Concurrent
44
55 describe FixedThreadPool do
66
7+ let ( :latch ) { Concurrent ::CountDownLatch . new }
8+
79 let! ( :num_threads ) { 5 }
810 subject { described_class . new ( num_threads ) }
911
1012 after ( :each ) do
1113 subject . kill
12- sleep ( 0.1 )
14+ subject . wait_for_termination ( 0.1 )
1315 end
1416
1517 it_should_behave_like :thread_pool
@@ -82,13 +84,15 @@ module Concurrent
8284
8385 it 'returns :num_threads while running' do
8486 10 . times { subject . post { nil } }
85- sleep ( 0.1 )
87+ subject . post { latch . count_down }
88+ latch . wait ( 0.1 )
8689 expect ( subject . min_length ) . to eq num_threads
8790 end
8891
8992 it 'returns :num_threads once shutdown' do
9093 10 . times { subject . post { nil } }
91- sleep ( 0.1 )
94+ subject . post { latch . count_down }
95+ latch . wait ( 0.1 )
9296 subject . shutdown
9397 subject . wait_for_termination ( 1 )
9498 expect ( subject . min_length ) . to eq num_threads
@@ -103,13 +107,15 @@ module Concurrent
103107
104108 it 'returns :num_threads while running' do
105109 10 . times { subject . post { nil } }
106- sleep ( 0.1 )
110+ subject . post { latch . count_down }
111+ latch . wait ( 0.1 )
107112 expect ( subject . max_length ) . to eq num_threads
108113 end
109114
110115 it 'returns :num_threads once shutdown' do
111116 10 . times { subject . post { nil } }
112- sleep ( 0.1 )
117+ subject . post { latch . count_down }
118+ latch . wait ( 0.1 )
113119 subject . shutdown
114120 subject . wait_for_termination ( 1 )
115121 expect ( subject . max_length ) . to eq num_threads
@@ -120,7 +126,8 @@ module Concurrent
120126
121127 it 'returns :num_threads while running' do
122128 10 . times { subject . post { nil } }
123- sleep ( 0.1 )
129+ subject . post { latch . count_down }
130+ latch . wait ( 0.1 )
124131 expect ( subject . length ) . to eq num_threads
125132 end
126133 end
@@ -133,13 +140,15 @@ module Concurrent
133140
134141 it 'returns :num_threads while running' do
135142 10 . times { subject . post { nil } }
136- sleep ( 0.1 )
143+ subject . post { latch . count_down }
144+ latch . wait ( 0.1 )
137145 expect ( subject . largest_length ) . to eq num_threads
138146 end
139147
140148 it 'returns :num_threads once shutdown' do
141149 10 . times { subject . post { nil } }
142- sleep ( 0.1 )
150+ subject . post { latch . count_down }
151+ latch . wait ( 0.1 )
143152 subject . shutdown
144153 subject . wait_for_termination ( 1 )
145154 expect ( subject . largest_length ) . to eq num_threads
0 commit comments