Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reentrant mutext spec and make it run on all rubies #555

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions spec/rspec/support/reentrant_mutex_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,26 @@
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')
it 'waits when trying to lock from another Fiber' do
mutex.synchronize do
called = false
ready = false

f =
Fiber.new do
ready = true
mutex.send(:enter)
expect(called).to eq true
end

main_thread = Thread.current
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
t = Thread.new do
Thread.pass until ready && main_thread.stop?
called = true
end
f.resume
t.join
end
end
end