Skip to content

Commit 8f35185

Browse files
authored
Test that connect_timeout does not include the time needed to acquire a connection from the pool (#1091)
1 parent bbe1746 commit 8f35185

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/client.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using JSON
1111
using Test
1212
using URIs
1313
using InteractiveUtils: @which
14+
using ConcurrentUtilities
1415

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

327+
@testset "connect_timeout does not include the time needed to acquire a connection from the pool" begin
328+
connection_limit = HTTP.Connections.TCP_POOL[].max
329+
try
330+
dummy_conn = HTTP.Connection(Sockets.TCPSocket())
331+
HTTP.set_default_connection_limit!(1)
332+
@assert HTTP.Connections.TCP_POOL[].max == 1
333+
# drain the pool
334+
acquire(()->dummy_conn, HTTP.Connections.TCP_POOL[], HTTP.Connections.connectionkey(dummy_conn))
335+
# Put it back in 10 seconds
336+
Timer(t->HTTP.Connections.releaseconnection(dummy_conn, false), 10; interval=0)
337+
# If we count the time it takes to acquire the connection from the pool, we'll get a timeout error.
338+
HTTP.get("https://$httpbin/get"; connection_timeout=5, retry=false, socket_type_tls=Sockets.TCPSocket)
339+
@test true # if we get here, we didn't timeout
340+
finally
341+
HTTP.set_default_connection_limit!(connection_limit)
342+
end
343+
end
344+
326345
@testset "Retry all resolved IP addresses" begin
327346
# See issue https://github.com/JuliaWeb/HTTP.jl/issues/672
328347
# Bit tricky to test, but can at least be tested if localhost

0 commit comments

Comments
 (0)