Skip to content

Commit

Permalink
fix timeout header value, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaykm committed May 3, 2021
1 parent b80cd80 commit 8574b40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/curl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,22 @@ end

function grpc_timeout_header_val(timeout::Real)
if round(Int, timeout) == timeout
timeout_secs = round(Int, timeout)
timeout_secs = round(Int64, timeout)
return "$(timeout_secs)S"
end
timeout *= 1000
if round(Int, timeout) == timeout
timeout_millisecs = round(Int, timeout)
timeout_millisecs = round(Int64, timeout)
return "$(timeout_millisecs)m"
end
timeout *= 1000
if round(Int, timeout) == timeout
timeout_microsecs = round(Int, timeout)
timeout_microsecs = round(Int64, timeout)
return "$(timeout_microsecs)u"
end
timeout *= 1000
if round(Int, timeout) == timeout
timeout_nanosecs = round(Int, timeout)
return "$(timeout_nanosecs)n"
end
timeout_nanosecs = round(Int64, timeout)
return "$(timeout_nanosecs)n"
end

function grpc_headers(; timeout::Real=Inf)
Expand Down
12 changes: 12 additions & 0 deletions test/runtests_routeguide.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function test_generate()
end
end

function test_timeout_header_values()
@testset "timeout header" begin
@test "100S" == gRPCClient.grpc_timeout_header_val(100)
@test "100010m" == gRPCClient.grpc_timeout_header_val(100.01)
@test "100000100u" == gRPCClient.grpc_timeout_header_val(100.0001)
@test "100000010000n" == gRPCClient.grpc_timeout_header_val(100.00001)
end
end

# switch off host verification for tests
if isempty(get(ENV, "JULIA_NO_VERIFY_HOSTS", ""))
ENV["JULIA_NO_VERIFY_HOSTS"] = "**"
Expand All @@ -70,6 +79,9 @@ server_endpoint = isempty(ARGS) ? "http://localhost:10000/" : ARGS[1]
else
@info("skipping code generation on Windows to avoid needing batch file execution permissions")
end

test_timeout_header_values()

include("test_routeclient.jl")
serverproc = start_server()

Expand Down

0 comments on commit 8574b40

Please sign in to comment.