|
465 | 465 |
|
466 | 466 | context ':caller_runs' do
|
467 | 467 |
|
468 |
| - subject do |
| 468 | + let(:executor) do |
469 | 469 | described_class.new(
|
470 | 470 | min_threads: 1,
|
471 | 471 | max_threads: 1,
|
|
475 | 475 | )
|
476 | 476 | end
|
477 | 477 |
|
| 478 | + after(:each) do |
| 479 | + # need to replicate this w/i scope otherwise rspec may complain |
| 480 | + executor.kill |
| 481 | + executor.wait_for_termination(0.1) |
| 482 | + end |
| 483 | + |
478 | 484 | specify '#post does not create any new threads when the queue is at capacity' do
|
479 | 485 | trigger = Concurrent::Event.new
|
480 | 486 | initial = Thread.list.length
|
481 | 487 |
|
482 | 488 | # Post several tasks to the executor. Has to be a new thread,
|
483 | 489 | # because it will start blocking once the queue fills up.
|
484 | 490 | Thread.new do
|
485 |
| - 5.times{ subject.post{ trigger.wait } } |
| 491 | + 5.times{ executor.post{ trigger.wait } } |
486 | 492 | end
|
487 | 493 |
|
488 | 494 | expect(Thread.list.length).to be < initial + 1 + 5
|
|
494 | 500 | specify '#<< executes the task on the current thread when the queue is at capacity' do
|
495 | 501 | trigger = Concurrent::Event.new
|
496 | 502 | latch = Concurrent::CountDownLatch.new(5)
|
497 |
| - subject.post{ trigger.wait } |
498 |
| - 5.times{|i| subject << proc { latch.count_down } } |
| 503 | + executor.post{ trigger.wait } |
| 504 | + 5.times{|i| executor << proc { latch.count_down } } |
499 | 505 | latch.wait(0.1)
|
500 | 506 | trigger.set
|
501 | 507 | end
|
502 | 508 |
|
503 | 509 | specify '#post executes the task on the current thread when the queue is at capacity' do
|
504 | 510 | trigger = Concurrent::Event.new
|
505 | 511 | latch = Concurrent::CountDownLatch.new(5)
|
506 |
| - subject.post{ trigger.wait } |
507 |
| - 5.times{|i| subject.post{ latch.count_down } } |
| 512 | + executor.post{ trigger.wait } |
| 513 | + 5.times{|i| executor.post{ latch.count_down } } |
508 | 514 | latch.wait(0.1)
|
509 | 515 | trigger.set
|
510 | 516 | end
|
511 | 517 |
|
512 | 518 | specify '#post executes the task on the current thread when the executor is shutting down' do
|
513 | 519 | latch = Concurrent::CountDownLatch.new(1)
|
514 |
| - subject.shutdown |
515 |
| - subject.post{ latch.count_down } |
| 520 | + executor.shutdown |
| 521 | + executor.post{ latch.count_down } |
516 | 522 | latch.wait(0.1)
|
517 | 523 | end
|
518 | 524 |
|
519 | 525 | specify '#<< executes the task on the current thread when the executor is shutting down' do
|
520 | 526 | latch = Concurrent::CountDownLatch.new(1)
|
521 |
| - subject.shutdown |
522 |
| - subject << proc { latch.count_down } |
| 527 | + executor.shutdown |
| 528 | + executor << proc { latch.count_down } |
523 | 529 | latch.wait(0.1)
|
524 | 530 | end
|
525 | 531 | end
|
|
0 commit comments