mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Call scheduler.block instead of scheduler.kernel_sleep for blocking Queue/SizedQueue operations
* scheduler.unblock was already already called before but with no corresponding scheduler.block * add test that Queue#pop makes the scheduler wait until it gets an element.
This commit is contained in:
parent
738a089b3a
commit
9472d16061
4 changed files with 35 additions and 9 deletions
|
|
@ -115,6 +115,31 @@ class TestFiberMutex < Test::Unit::TestCase
|
|||
assert processed == 3
|
||||
end
|
||||
|
||||
def test_queue_pop_waits
|
||||
queue = Queue.new
|
||||
running = false
|
||||
|
||||
thread = Thread.new do
|
||||
scheduler = Scheduler.new
|
||||
Thread.current.scheduler = scheduler
|
||||
|
||||
result = nil
|
||||
Fiber.schedule do
|
||||
result = queue.pop
|
||||
end
|
||||
|
||||
running = true
|
||||
scheduler.run
|
||||
result
|
||||
end
|
||||
|
||||
Thread.pass until running
|
||||
sleep 0.1
|
||||
|
||||
queue << :done
|
||||
assert_equal :done, thread.value
|
||||
end
|
||||
|
||||
def test_mutex_deadlock
|
||||
err = /No live threads left. Deadlock\?/
|
||||
assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], err, success: false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue