Skip to content

Commit

Permalink
Fix failing specs on FreeBSD (#15093)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden authored Oct 19, 2024
1 parent 126f037 commit fa25838
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
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 %}

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
23 changes: 13 additions & 10 deletions spec/std/socket/socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ describe Socket, tags: "network" do
sock.type.should eq(Socket::Type::DGRAM)
{% end %}

error = expect_raises(Socket::Error) do
TCPSocket.new(family: :unix)
end
error.os_error.should eq({% if flag?(:win32) %}
WinError::WSAEPROTONOSUPPORT
{% elsif flag?(:wasi) %}
WasiError::PROTONOSUPPORT
{% else %}
Errno.new(LibC::EPROTONOSUPPORT)
{% end %})
{% unless flag?(:freebsd) %}
# for some reason this doesn't fail on freebsd
error = expect_raises(Socket::Error) do
TCPSocket.new(family: :unix)
end
error.os_error.should eq({% if flag?(:win32) %}
WinError::WSAEPROTONOSUPPORT
{% elsif flag?(:wasi) %}
WasiError::PROTONOSUPPORT
{% else %}
Errno.new(LibC::EPROTONOSUPPORT)
{% end %})
{% end %}
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/std/socket/udp_socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ describe UDPSocket, tags: "network" do
# TODO: figure out why updating `multicast_loopback` produces a
# `setsockopt 18: Invalid argument` error
pending "joins and transmits to multicast groups"
elsif {{ flag?(:freebsd) }} && family == Socket::Family::INET6
# FIXME: fails with "Error sending datagram to [ipv6]:port: Network is unreachable"
pending "joins and transmits to multicast groups"
else
it "joins and transmits to multicast groups" do
udp = UDPSocket.new(family)
Expand Down

0 comments on commit fa25838

Please sign in to comment.