Skip to content

Commit

Permalink
#read_timeout=, #write_timeout=, #connect_timeout=
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Sep 3, 2024
1 parent 0ab6d02 commit 36cd248
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions spec/std/http/client/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ module HTTP
test_server("localhost", 0, 0.5, write_response: false) do |server|
client = Client.new("localhost", server.local_address.port)
expect_raises(IO::TimeoutError, {% if flag?(:win32) %} "WSARecv timed out" {% else %} "Read timed out" {% end %}) do
client.read_timeout = 0.001
client.read_timeout = 1.millisecond
client.get("/?sleep=1")
end
end
Expand All @@ -365,7 +365,7 @@ module HTTP
test_server("localhost", 0, 0, write_response: false) do |server|
client = Client.new("localhost", server.local_address.port)
expect_raises(IO::TimeoutError, {% if flag?(:win32) %} "WSASend timed out" {% else %} "Write timed out" {% end %}) do
client.write_timeout = 0.001
client.write_timeout = 1.millisecond
client.post("/", body: "a" * 5_000_000)
end
end
Expand All @@ -374,7 +374,7 @@ module HTTP
it "tests connect_timeout" do
test_server("localhost", 0, 0) do |server|
client = Client.new("localhost", server.local_address.port)
client.connect_timeout = 0.5
client.connect_timeout = 0.5.seconds
client.get("/")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/server/server_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe HTTP::Server do
begin
ch.receive
client = HTTP::Client.new(address.address, address.port, client_context)
client.read_timeout = client.connect_timeout = 3
client.read_timeout = client.connect_timeout = 3.seconds
client.get("/").body.should eq "ok"
ensure
ch.send nil
Expand Down
4 changes: 2 additions & 2 deletions spec/std/io/io_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ describe IO do
write.puts "hello"
slice = Bytes.new 1024

read.read_timeout = 1
read.read_timeout = 1.second
read.read(slice).should eq(6)

expect_raises(IO::TimeoutError) do
read.read_timeout = 0.0000001
read.read_timeout = 0.1.microseconds
read.read(slice)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/socket/socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe Socket, tags: "network" do
server = Socket.new(Socket::Family::INET, Socket::Type::STREAM, Socket::Protocol::TCP)
port = unused_local_port
server.bind("0.0.0.0", port)
server.read_timeout = 0.1
server.read_timeout = 0.1.seconds
server.listen

expect_raises(IO::TimeoutError) { server.accept }
Expand Down
4 changes: 2 additions & 2 deletions spec/std/socket/unix_socket_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ describe UNIXSocket do
it "tests read and write timeouts" do
UNIXSocket.pair do |left, right|
# BUG: shrink the socket buffers first
left.write_timeout = 0.0001
right.read_timeout = 0.0001
left.write_timeout = 0.1.milliseconds
right.read_timeout = 0.1.milliseconds
buf = ("a" * IO::DEFAULT_BUFFER_SIZE).to_slice

expect_raises(IO::TimeoutError, "Write timed out") do
Expand Down

0 comments on commit 36cd248

Please sign in to comment.