Skip to content

Commit

Permalink
Test that connect_timeout does not include the time needed to acqui…
Browse files Browse the repository at this point in the history
…re a connection from the pool (#1091)
  • Loading branch information
Drvi authored Aug 16, 2023
1 parent bbe1746 commit 8f35185
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using JSON
using Test
using URIs
using InteractiveUtils: @which
using ConcurrentUtilities

# test we can adjust default_connection_limit
for x in (10, 12)
Expand Down Expand Up @@ -323,6 +324,24 @@ end
HTTP.get("http://$httpbin/delay/1"; readtimeout=2, retry=false)
end

@testset "connect_timeout does not include the time needed to acquire a connection from the pool" begin
connection_limit = HTTP.Connections.TCP_POOL[].max
try
dummy_conn = HTTP.Connection(Sockets.TCPSocket())
HTTP.set_default_connection_limit!(1)
@assert HTTP.Connections.TCP_POOL[].max == 1
# drain the pool
acquire(()->dummy_conn, HTTP.Connections.TCP_POOL[], HTTP.Connections.connectionkey(dummy_conn))
# Put it back in 10 seconds
Timer(t->HTTP.Connections.releaseconnection(dummy_conn, false), 10; interval=0)
# If we count the time it takes to acquire the connection from the pool, we'll get a timeout error.
HTTP.get("https://$httpbin/get"; connection_timeout=5, retry=false, socket_type_tls=Sockets.TCPSocket)
@test true # if we get here, we didn't timeout
finally
HTTP.set_default_connection_limit!(connection_limit)
end
end

@testset "Retry all resolved IP addresses" begin
# See issue https://github.com/JuliaWeb/HTTP.jl/issues/672
# Bit tricky to test, but can at least be tested if localhost
Expand Down

0 comments on commit 8f35185

Please sign in to comment.