Skip to content
Merged
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
20 changes: 20 additions & 0 deletions spec/lib/ember_cli/dev_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def listen(host, port, status: 200, body: "")
end

@thread = Thread.new { @server.start }
wait_until_running

@port
end
Expand All @@ -245,6 +246,25 @@ def shutdown
@server&.shutdown
@thread&.join
end

private

# Not `shutdown` straight after `Thread.new`: `GenericServer#shutdown` is
# a no-op until `#start` has set up its shutdown pipe, and a new thread
# is not guaranteed to have run by the time the example finishes (on
# Ruby 4.0 it usually has not). Shutting down such a server leaves it
# looping forever, and the join in `#shutdown` never returns.
def wait_until_running
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5

until @server.status == :Running
if Process.clock_gettime(Process::CLOCK_MONOTONIC) > deadline
raise "The stub development server did not start within 5 seconds"
end

sleep 0.01
end
end
end

def null_server
Expand Down