Skip to content

Commit

Permalink
add tests for connect timeout (#30)
Browse files Browse the repository at this point in the history
Adding a test to verify whether connect timeouts take effect if specified.
  • Loading branch information
tanmaykm authored Jul 20, 2022
1 parent e02547d commit 904493e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/runtests_errors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ server_endpoint = isempty(ARGS) ? "http://localhost:10000/" : ARGS[1]
@info("skipping code generation on Windows to avoid needing batch file execution permissions")
end
include("test_grpcerrors.jl")

@info("testing connect timeouts")
test_connect_timeout()

serverproc = start_server()

@info("testing grpcerrors...")
Expand Down
21 changes: 21 additions & 0 deletions test/test_grpcerrors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ function test_blocking_client(server_endpoint::String)
end
end

function test_connect_timeout()
timeout_server_endpoint = "http://10.255.255.1/" # a non routable IP
timeout_secs = 5
client = GRPCErrorsBlockingClient(timeout_server_endpoint; verbose=false, connect_timeout=timeout_secs)
@testset "connect timeout" begin
data = GrpcerrorsClients.Data(; mode=1, param=0)
t1 = time()
try
_, status_future = GrpcerrorsClients.SimpleRPC(client, data)
gRPCCheck(status_future)
error("error not caught")
catch ex
t2 = time()
@test isa(ex, gRPCServiceCallException)
@test ex.message == StatusCode.DEADLINE_EXCEEDED.message
@test ex.grpc_status == StatusCode.DEADLINE_EXCEEDED.code
@test (timeout_secs - 1) <= (t2 - t1) <= (timeout_secs + 1)
end
end
end

function test_clients(server_endpoint::String)
@info("testing blocking client")
test_blocking_client(server_endpoint)
Expand Down

0 comments on commit 904493e

Please sign in to comment.