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 failing specs on FreeBSD #15093

Merged
merged 2 commits into from
Oct 19, 2024
Merged
Changes from 1 commit
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
24 changes: 14 additions & 10 deletions spec/std/signal_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,48 @@ pending_interpreted describe: "Signal" do
end

{% unless flag?(:win32) %}
# can't use SIGUSR1/SIGUSR2 on FreeBSD because Boehm uses them to suspend/resume threads
signal1 = {% if flag?(:freebsd) %} Signal.new(LibC::SIGRTMAX - 1) {% else %} Signal::USR1 {% end %}
signal2 = {% if flag?(:freebsd) %} Signal.new(LibC::SIGRTMAX - 2) {% else %} Signal::USR2 {% end %}
Comment on lines +22 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Could we use RT signals on all platforms, instead of USR1, USR2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, though I'm not sure all platforms have SIGRT signals, and USR1 and USR2 should usually be available ... I wonder why would Boehm use USR1 and USR2 when it can use SIGRT signals (and does so, but only when told to) 🤷


it "runs a signal handler" do
ran = false
Signal::USR1.trap do
signal1.trap do
ran = true
end
Process.signal Signal::USR1, Process.pid
Process.signal signal1, Process.pid
10.times do |i|
break if ran
sleep 0.1.seconds
end
ran.should be_true
ensure
Signal::USR1.reset
signal1.reset
end

it "ignores a signal" do
Signal::USR2.ignore
Process.signal Signal::USR2, Process.pid
signal2.ignore
Process.signal signal2, Process.pid
end

it "allows chaining of signals" do
ran_first = false
ran_second = false

Signal::USR1.trap { ran_first = true }
existing = Signal::USR1.trap_handler?
signal1.trap { ran_first = true }
existing = signal1.trap_handler?

Signal::USR1.trap do |signal|
signal1.trap do |signal|
existing.try &.call(signal)
ran_second = true
end

Process.signal Signal::USR1, Process.pid
Process.signal signal1, Process.pid
sleep 0.1.seconds
ran_first.should be_true
ran_second.should be_true
ensure
Signal::USR1.reset
signal1.reset
end

it "CHLD.reset sets default Crystal child handler" do
Expand Down