Skip to content

Commit

Permalink
Add spec for HTTP::Server#close (crystal-lang#5958)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and Ezra Stevens committed Oct 1, 2018
1 parent fe86d96 commit 0dd5ea6
Showing 1 changed file with 35 additions and 0 deletions.
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

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

0 comments on commit 0dd5ea6

Please sign in to comment.