Skip to content

Commit 904493e

Browse files
authored
add tests for connect timeout (#30)
Adding a test to verify whether connect timeouts take effect if specified.
1 parent e02547d commit 904493e

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

test/runtests_errors.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ server_endpoint = isempty(ARGS) ? "http://localhost:10000/" : ARGS[1]
7171
@info("skipping code generation on Windows to avoid needing batch file execution permissions")
7272
end
7373
include("test_grpcerrors.jl")
74+
75+
@info("testing connect timeouts")
76+
test_connect_timeout()
77+
7478
serverproc = start_server()
7579

7680
@info("testing grpcerrors...")

test/test_grpcerrors.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ function test_blocking_client(server_endpoint::String)
142142
end
143143
end
144144

145+
function test_connect_timeout()
146+
timeout_server_endpoint = "http://10.255.255.1/" # a non routable IP
147+
timeout_secs = 5
148+
client = GRPCErrorsBlockingClient(timeout_server_endpoint; verbose=false, connect_timeout=timeout_secs)
149+
@testset "connect timeout" begin
150+
data = GrpcerrorsClients.Data(; mode=1, param=0)
151+
t1 = time()
152+
try
153+
_, status_future = GrpcerrorsClients.SimpleRPC(client, data)
154+
gRPCCheck(status_future)
155+
error("error not caught")
156+
catch ex
157+
t2 = time()
158+
@test isa(ex, gRPCServiceCallException)
159+
@test ex.message == StatusCode.DEADLINE_EXCEEDED.message
160+
@test ex.grpc_status == StatusCode.DEADLINE_EXCEEDED.code
161+
@test (timeout_secs - 1) <= (t2 - t1) <= (timeout_secs + 1)
162+
end
163+
end
164+
end
165+
145166
function test_clients(server_endpoint::String)
146167
@info("testing blocking client")
147168
test_blocking_client(server_endpoint)

0 commit comments

Comments
 (0)