Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Curl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ mutable struct gRPCRequest
# curl_easy_setopt(easy_handle, CURLOPT_VERBOSE, UInt32(1))

curl_easy_setopt(easy_handle, CURLOPT_URL, url)
curl_easy_setopt(easy_handle, CURLOPT_TIMEOUT, deadline)
curl_easy_setopt(easy_handle, CURLOPT_TIMEOUT, Clong(ceil(deadline)))
curl_easy_setopt(easy_handle, CURLOPT_CONNECTTIMEOUT, Clong(ceil(deadline)))
curl_easy_setopt(easy_handle, CURLOPT_PIPEWAIT, Clong(1))
curl_easy_setopt(easy_handle, CURLOPT_POST, Clong(1))
curl_easy_setopt(easy_handle, CURLOPT_CUSTOMREQUEST, "POST")
Expand Down
127 changes: 82 additions & 45 deletions src/gRPCClient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,29 @@ export gRPCServiceCallException


@setup_workload begin
# We don't have a Julia gRPC server so call my Linode's public gRPC endpoint
TEST_HOST = "172.238.177.88"
# TODO: change this to port 80 to fix issues with corporate firewalls
TEST_PORT = 8001
function _get_precompile_host()
if "GRPC_PRECOMPILE_SERVER_HOST" in keys(ENV)
ENV["GRPC_PRECOMPILE_SERVER_HOST"]
else
# We don't have a Julia gRPC server so call my Linode's public gRPC endpoint
"172.238.177.88"
end
end

function _get_precompile_port()
if "GRPC_PRECOMPILE_SERVER_PORT" in keys(ENV)
parse(UInt16, ENV["GRPC_PRECOMPILE_SERVER_PORT"])
else
8001
end
end

TEST_HOST = _get_precompile_host()
TEST_PORT = _get_precompile_port()

@compile_workload begin
"GRPC_PRECOMPILE_DISABLE" in keys(ENV) && return

include("../test/gen/test/test_pb.jl")

# Initialize the gRPC package - grpc_shutdown() does the opposite for use with Revise.
Expand All @@ -127,47 +144,67 @@ export gRPCServiceCallException
# Unary
client_unary = TestService_TestRPC_Client(TEST_HOST, TEST_PORT)

# Sync API
test_response = grpc_sync_request(client_unary, TestRequest(1, Vector{UInt64}()))

# Async API
request = grpc_async_request(client_unary, TestRequest(1, Vector{UInt64}()))
test_response = grpc_async_await(client_unary, request)

# Streaming
@static if VERSION >= v"1.12"

# Request
client_request = TestService_TestClientStreamRPC_Client(TEST_HOST, TEST_PORT)
request_c = Channel{TestRequest}(16)
put!(request_c, TestRequest(1, zeros(UInt64, 1)))
close(request_c)
test_response = grpc_async_await(
client_request,
grpc_async_request(client_request, request_c),
)

# Response
client_response = TestService_TestServerStreamRPC_Client(TEST_HOST, TEST_PORT)
response_c = Channel{TestResponse}(16)
req = grpc_async_request(
client_response,
TestRequest(1, zeros(UInt64, 1)),
response_c,
)
test_response = take!(response_c)
grpc_async_await(req)

# Bidirectional
client_bidirectional =
TestService_TestBidirectionalStreamRPC_Client(TEST_HOST, TEST_PORT)
request_c = Channel{TestRequest}(16)
response_c = Channel{TestResponse}(16)
put!(request_c, TestRequest(1, zeros(UInt64, 1)))
req = grpc_async_request(client_bidirectional, request_c, response_c)
test_response = take!(response_c)
close(request_c)
grpc_async_await(req)
try
# Sync API
test_response =
grpc_sync_request(client_unary, TestRequest(1, Vector{UInt64}()))

# Async API
request = grpc_async_request(client_unary, TestRequest(1, Vector{UInt64}()))
test_response = grpc_async_await(client_unary, request)

# Streaming
@static if VERSION >= v"1.12"

# Request
client_request =
TestService_TestClientStreamRPC_Client(TEST_HOST, TEST_PORT)
request_c = Channel{TestRequest}(16)
put!(request_c, TestRequest(1, zeros(UInt64, 1)))
close(request_c)
test_response = grpc_async_await(
client_request,
grpc_async_request(client_request, request_c),
)

# Response
client_response =
TestService_TestServerStreamRPC_Client(TEST_HOST, TEST_PORT)
response_c = Channel{TestResponse}(16)
req = grpc_async_request(
client_response,
TestRequest(1, zeros(UInt64, 1)),
response_c,
)
test_response = take!(response_c)
grpc_async_await(req)

# Bidirectional
client_bidirectional =
TestService_TestBidirectionalStreamRPC_Client(TEST_HOST, TEST_PORT)
request_c = Channel{TestRequest}(16)
response_c = Channel{TestResponse}(16)
put!(request_c, TestRequest(1, zeros(UInt64, 1)))
req = grpc_async_request(client_bidirectional, request_c, response_c)
test_response = take!(response_c)
close(request_c)
grpc_async_await(req)
end
catch ex
!isa(ex, gRPCServiceCallException) &&
ex.code == DEADLINE_EXCEEDED &&
rethrow(ex)

@warn """
DEADLINE_EXCEEDED during gRPCClient.jl precompile

A dedicated server for allowing this package to precompile is provided to the public but is not accessible from this network.
If you care about this you can consider the following options:
- Request that your network administrator allow connections to this address on TCP: $(TEST_HOST):$(TEST_PORT)
- Add a precompile block to your own package which calls an accessible gRPC server
- Run your own instance of the Go gRPC test server in public mode `./grpc_test_server -public` and set GRPC_PRECOMPILE_SERVER_HOST and GRPC_PRECOMPILE_SERVER_PORT environment variables to point to it
- Set the GRPC_PRECOMPILE_DISABLE environment variable to disable gRPCClient.jl precompiliation and this message
"""
end

grpc_shutdown()
Expand Down
4 changes: 2 additions & 2 deletions test/go/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func main() {
}

if *publicMode {
host = "::"
log.Printf("Listening on [%s]:%d in public mode", host, port)
host = ""
log.Printf("Listening on [::]:%d in public mode", port)
log.Println("(len(response.data) will always be 1)")
} else {
log.Printf("Listening on %s:%d in test mode", host, port)
Expand Down