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
35 changes: 35 additions & 0 deletions spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,41 @@ module HTTP

server_done.should be_false
end

describe "#close" do
it "closes gracefully" do
server = Server.new do |context|
context.response.flush
context.response.puts "foo"
context.response.flush

Fiber.yield
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is no doc for Fiber.yield, could you please explain how it works here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fiber.yield gives the scheduler the possibility to yield execution to a different fiber.
This was a sloppy implementation though and has been replaced since then in #6953


context.response.puts "bar"
end

address = server.bind_unused_port
spawn server.listen

TCPSocket.open(address.address, address.port) do |socket|
socket << "GET / HTTP/1.1\r\n\r\n"

while true
line = socket.gets || break
break if line.empty?
end

socket = HTTP::ChunkedContent.new(socket)

socket.gets.should eq "foo"

server.close

socket.closed?.should be_false
socket.gets.should eq "bar"
end
end
end
end

describe HTTP::Server::RequestProcessor do
Expand Down