Skip to content

Commit

Permalink
MT: workaround regular timeouts in HTTP::Server specs
Browse files Browse the repository at this point in the history
The core of the issue is a synchronization issue between fibers that
test edge cases in HTTP::Server, for example what's happening after
closing the fiber (from another fiber) while we have no guarantee that
the server is actually listening.

I couldn't find a proper way to fix the issue. The only solution that
fixed the reproducibility of the issue was adding a one millisecond
sleep after starting the server.

closes crystal-lang#13211
  • Loading branch information
ysbaddaden committed Dec 15, 2023
1 parent 0b251d4 commit 578f9f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 1 addition & 4 deletions spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ describe HTTP::Server do
server = HTTP::Server.new { }
server.bind_unused_port

spawn do
run_server(server) do
server.close
sleep 0.001
end

server.listen
end

it "closes the server" do
Expand Down
5 changes: 5 additions & 0 deletions spec/std/http/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def run_server(server, &)
wait_for { server.listening? }
wait_until_blocked f

{% if flag?(:preview_mt) %}
# avoids fiber synchronization issues in specs, like closing the server
# before we properly listen, ...
sleep 0.001
{% end %}
yield server_done
ensure
server.close unless server.closed?
Expand Down

0 comments on commit 578f9f7

Please sign in to comment.