File tree Expand file tree Collapse file tree 1 file changed +35
-5
lines changed Expand file tree Collapse file tree 1 file changed +35
-5
lines changed Original file line number Diff line number Diff line change 253
253
end
254
254
255
255
specify 'a #post task is never executed when the queue is at capacity' do
256
- executed = Concurrent ::AtomicFixnum . new ( 0 )
257
- 1000 . times do
258
- subject . post { sleep ; executed . increment }
256
+ lock = Mutex . new
257
+ lock . lock
258
+ initial_executed = Concurrent ::AtomicFixnum . new ( 0 )
259
+ subsequent_executed = Concurrent ::AtomicFixnum . new ( 0 )
260
+
261
+ # Fill up all the threads (with a task that won't run until
262
+ # lock.unlock is called)
263
+ max_threads . times do
264
+ subject . post { lock . lock ; initial_executed . increment ; lock . unlock }
259
265
end
260
- sleep ( 0.1 )
261
- expect ( executed . value ) . to be 0
266
+
267
+ # Fill up the queue (with a task that won't run until
268
+ # lock.unlock is called)
269
+ max_queue . times do
270
+ subject . post { lock . lock ; initial_executed . increment ; lock . unlock }
271
+ end
272
+
273
+ # Inject 100 more tasks, which should be dropped without an exception
274
+ 100 . times do
275
+ subject . post { subsequent_executed . increment ; }
276
+ end
277
+
278
+ # Unlock the lock, so that the tasks in the threads and on
279
+ # the queue can run to completion
280
+ lock . unlock
281
+
282
+ # Wait for all tasks to finish
283
+ subject . shutdown
284
+ subject . wait_for_termination
285
+
286
+ # The tasks should have run until all the threads and the
287
+ # queue filled up...
288
+ expect ( initial_executed . value ) . to be ( max_threads + max_queue )
289
+
290
+ # ..but been dropped after that
291
+ expect ( subsequent_executed . value ) . to be 0
262
292
end
263
293
264
294
specify 'a #<< task is never executed when the queue is at capacity' do
You can’t perform that action at this time.
0 commit comments