@@ -122,27 +122,33 @@ module Concurrent
122
122
end
123
123
124
124
specify '#post does not create any new threads when the queue is at capacity' do
125
- 2 . times { subject . post { sleep ( 1 ) } }
126
- sleep ( 0.1 )
127
- expected = Thread . list . length
128
- subject . post { nil }
129
- Thread . list . length . should eq expected
125
+ initial = Thread . list . length
126
+ 5 . times { subject . post { sleep ( 0.1 ) } }
127
+ Thread . list . length . should < initial + 5
128
+ end
129
+
130
+ specify '#post executes the task on the current thread when the queue is at capacity' do
131
+ subject . should_receive ( :handle_overflow ) . with ( any_args ) . at_least ( :once )
132
+ 5 . times { subject . post { sleep ( 0.1 ) } }
130
133
end
131
134
132
135
specify '#post executes the task on the current thread when the queue is at capacity' do
133
- 2 . times { subject . post { sleep ( 1 ) } }
136
+ bucket = [ ]
137
+ 5 . times { |i | subject . post { bucket . push ( i ) } }
134
138
sleep ( 0.1 )
135
- expected = false
136
- subject . post { expected = true }
137
- expected . should be_true
139
+ bucket . sort . should eq [ 0 , 1 , 2 , 3 , 4 ]
138
140
end
139
141
140
142
specify '#<< executes the task on the current thread when the queue is at capacity' do
141
- 2 . times { subject . post { sleep ( 1 ) } }
143
+ subject . should_receive ( :handle_overflow ) . with ( any_args ) . at_least ( :once )
144
+ 5 . times { subject << proc { sleep ( 0.1 ) } }
145
+ end
146
+
147
+ specify '#post executes the task on the current thread when the queue is at capacity' do
148
+ bucket = [ ]
149
+ 5 . times { |i | subject << proc { bucket . push ( i ) } }
142
150
sleep ( 0.1 )
143
- expected = false
144
- subject << proc { expected = true }
145
- expected . should be_true
151
+ bucket . sort . should eq [ 0 , 1 , 2 , 3 , 4 ]
146
152
end
147
153
end
148
154
end
0 commit comments