From db1d2ca01003f2d734cedc21d6b7c13336640da4 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 9 Dec 2022 15:43:35 +1100 Subject: [PATCH 1/2] Run reentrant mutext spec on all rubies --- spec/rspec/support/reentrant_mutex_spec.rb | 38 ++++++++++------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/spec/rspec/support/reentrant_mutex_spec.rb b/spec/rspec/support/reentrant_mutex_spec.rb index 9bef54ee..3665c3de 100644 --- a/spec/rspec/support/reentrant_mutex_spec.rb +++ b/spec/rspec/support/reentrant_mutex_spec.rb @@ -28,27 +28,25 @@ order.join_all end - if RUBY_VERSION >= '3.0' - it 'waits when trying to lock from another Fiber' do - mutex.synchronize do - ready = false - f = Fiber.new do - expect { - ready = true - mutex.send(:enter) - raise 'should reach here: mutex is already locked on different Fiber' - }.to raise_error(Exception, 'waited correctly') - end - - main_thread = Thread.current - - t = Thread.new do - Thread.pass until ready && main_thread.stop? - main_thread.raise Exception, 'waited correctly' - end - f.resume - t.join + it 'waits when trying to lock from another Fiber' do + mutex.synchronize do + ready = false + f = Fiber.new do + expect { + ready = true + mutex.send(:enter) + raise 'should reach here: mutex is already locked on different Fiber' + }.to raise_error(Exception, 'waited correctly') end + + main_thread = Thread.current + + t = Thread.new do + Thread.pass until ready && main_thread.stop? + main_thread.raise Exception, 'waited correctly' + end + f.resume + t.join end end end From bf6f5b5feedbcc2e931cefbebe54834532268134 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 9 Dec 2022 16:25:23 +1100 Subject: [PATCH 2/2] Rework spec to not use exceptions --- spec/rspec/support/reentrant_mutex_spec.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/rspec/support/reentrant_mutex_spec.rb b/spec/rspec/support/reentrant_mutex_spec.rb index 3665c3de..a1057660 100644 --- a/spec/rspec/support/reentrant_mutex_spec.rb +++ b/spec/rspec/support/reentrant_mutex_spec.rb @@ -30,20 +30,21 @@ it 'waits when trying to lock from another Fiber' do mutex.synchronize do + called = false ready = false - f = Fiber.new do - expect { + + f = + Fiber.new do ready = true mutex.send(:enter) - raise 'should reach here: mutex is already locked on different Fiber' - }.to raise_error(Exception, 'waited correctly') - end + expect(called).to eq true + end main_thread = Thread.current t = Thread.new do Thread.pass until ready && main_thread.stop? - main_thread.raise Exception, 'waited correctly' + called = true end f.resume t.join