diff options
| author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-09-11 20:47:25 +1200 |
|---|---|---|
| committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-09-14 16:44:09 +1200 |
| commit | 0f613cc5f1bbe319ab916be905de263523ef5402 (patch) | |
| tree | 84f707d136241822a547a222e40a98efb57aca49 /test | |
| parent | 1a0cfe28390ce5d46f7b854eaad2b9b979c160de (diff) | |
Add support for ConditionVariable.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3434
Diffstat (limited to 'test')
| -rw-r--r-- | test/fiber/scheduler.rb | 4 | ||||
| -rw-r--r-- | test/fiber/test_mutex.rb | 37 |
2 files changed, 40 insertions, 1 deletions
diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index b03058a210..7003d88417 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -97,7 +97,9 @@ class Scheduler end def kernel_sleep(duration = nil) - @waiting[Fiber.current] = current_time + duration + if duration + @waiting[Fiber.current] = current_time + duration + end Fiber.yield diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb index 393a44fc2f..21034128a1 100644 --- a/test/fiber/test_mutex.rb +++ b/test/fiber/test_mutex.rb @@ -47,6 +47,43 @@ class TestFiberMutex < Test::Unit::TestCase thread.join end + def test_condition_variable + mutex = Mutex.new + condition = ConditionVariable.new + + signalled = 0 + + thread = Thread.new do + scheduler = Scheduler.new + Thread.current.scheduler = scheduler + + Fiber.schedule do + mutex.synchronize do + 3.times do + condition.wait(mutex) + signalled += 1 + end + end + end + + Fiber.schedule do + 3.times do + mutex.synchronize do + condition.signal + end + + sleep 0.1 + end + end + + scheduler.run + end + + thread.join + + assert signalled > 1 + end + def test_mutex_deadlock err = /No live threads left. Deadlock\?/ assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], err, success: false |
