|
|
|
@ -158,15 +158,27 @@ def create_stub(opts) |
|
|
|
|
|
|
|
|
|
GRPC.logger.info("... connecting securely to #{address}") |
|
|
|
|
stub_opts[:channel_args].merge!(compression_channel_args) |
|
|
|
|
if opts.test_case == "unimplemented_service" |
|
|
|
|
Grpc::Testing::UnimplementedService::Stub.new(address, creds, **stub_opts) |
|
|
|
|
else |
|
|
|
|
Grpc::Testing::TestService::Stub.new(address, creds, **stub_opts) |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
GRPC.logger.info("... connecting insecurely to #{address}") |
|
|
|
|
if opts.test_case == "unimplemented_service" |
|
|
|
|
Grpc::Testing::UnimplementedService::Stub.new( |
|
|
|
|
address, |
|
|
|
|
:this_channel_is_insecure, |
|
|
|
|
channel_args: compression_channel_args |
|
|
|
|
) |
|
|
|
|
else |
|
|
|
|
Grpc::Testing::TestService::Stub.new( |
|
|
|
|
address, |
|
|
|
|
:this_channel_is_insecure, |
|
|
|
|
channel_args: compression_channel_args |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# produces a string of null chars (\0) of length l. |
|
|
|
@ -502,6 +514,163 @@ class NamedTests |
|
|
|
|
op.wait |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def unimplemented_method |
|
|
|
|
begin |
|
|
|
|
resp = @stub.unimplemented_call(Empty.new) |
|
|
|
|
rescue GRPC::BadStatus => e |
|
|
|
|
if e.code != GRPC::Core::StatusCodes::UNIMPLEMENTED |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected status 12 (UNIMPLEMENTED). Received: #{e.code}" |
|
|
|
|
end |
|
|
|
|
rescue Exception => e |
|
|
|
|
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def unimplemented_service |
|
|
|
|
begin |
|
|
|
|
resp = @stub.unimplemented_call(Empty.new) |
|
|
|
|
rescue GRPC::BadStatus => e |
|
|
|
|
if e.code != GRPC::Core::StatusCodes::UNIMPLEMENTED |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected status 12 (UNIMPLEMENTED). Received: #{e.code}" |
|
|
|
|
end |
|
|
|
|
rescue Exception => e |
|
|
|
|
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def status_code_and_message |
|
|
|
|
|
|
|
|
|
# Function wide constants. |
|
|
|
|
message = "test status method" |
|
|
|
|
code = 2 |
|
|
|
|
status = GRPC::Core::StatusCodes::UNKNOWN |
|
|
|
|
|
|
|
|
|
# Testing with UnaryCall. |
|
|
|
|
payload = Payload.new(type: :COMPRESSABLE, body: nulls(1)) |
|
|
|
|
echo_status = EchoStatus.new(code: code, message: message) |
|
|
|
|
req = SimpleRequest.new(response_type: :COMPRESSABLE, |
|
|
|
|
response_size: 1, |
|
|
|
|
payload: payload, |
|
|
|
|
response_status: echo_status) |
|
|
|
|
seen_correct_exception = false |
|
|
|
|
begin |
|
|
|
|
resp = @stub.unary_call(req) |
|
|
|
|
rescue GRPC::BadStatus => e |
|
|
|
|
if e.code != status |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected status 2 (UNKOWN). Received: #{e.code}" |
|
|
|
|
elsif e.details != message |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected message #{message}. Received: #{e.details}" |
|
|
|
|
end |
|
|
|
|
seen_correct_exception = true |
|
|
|
|
rescue Exception => e |
|
|
|
|
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if not seen_correct_exception |
|
|
|
|
fail AssertionError, "Did not see expected status from UnaryCall" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# testing with FullDuplex |
|
|
|
|
req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters |
|
|
|
|
duplex_req = req_cls.new(payload: Payload.new(body: nulls(1)), |
|
|
|
|
response_type: :COMPRESSABLE, |
|
|
|
|
response_parameters: [p_cls.new(size: 1)], |
|
|
|
|
response_status: echo_status) |
|
|
|
|
seen_correct_exception = false |
|
|
|
|
begin |
|
|
|
|
resp = @stub.full_duplex_call([duplex_req]) |
|
|
|
|
resp.next # triggers initial req to be sent |
|
|
|
|
rescue GRPC::BadStatus => e |
|
|
|
|
if e.code != status |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected status 2 (UNKOWN). Received: #{e.code}" |
|
|
|
|
elsif e.details != message |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected message #{message}. Received: #{e.details}" |
|
|
|
|
end |
|
|
|
|
seen_correct_exception = true |
|
|
|
|
rescue Exception => e |
|
|
|
|
fail AssertionError, "Expected BadStatus. Received: #{e.inspect}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
if not seen_correct_exception |
|
|
|
|
fail AssertionError, "Did not see expected status from FullDuplexCall" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def custom_metadata |
|
|
|
|
|
|
|
|
|
# Function wide constants |
|
|
|
|
initial_metadata_key = "x-grpc-test-echo-initial" |
|
|
|
|
initial_metadata_value = "test_initial_metadata_value" |
|
|
|
|
trailing_metadata_key = "x-grpc-test-echo-trailing-bin" |
|
|
|
|
trailing_metadata_value = "\x0a\x0b\x0a\x0b\x0a\x0b" |
|
|
|
|
|
|
|
|
|
metadata = { |
|
|
|
|
initial_metadata_key => initial_metadata_value, |
|
|
|
|
trailing_metadata_key => trailing_metadata_value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Testing with UnaryCall |
|
|
|
|
payload = Payload.new(type: :COMPRESSABLE, body: nulls(1)) |
|
|
|
|
req = SimpleRequest.new(response_type: :COMPRESSABLE, |
|
|
|
|
response_size: 1, |
|
|
|
|
payload: payload) |
|
|
|
|
|
|
|
|
|
op = @stub.unary_call(req, metadata: metadata, return_op: true) |
|
|
|
|
op.execute |
|
|
|
|
if not op.metadata.has_key?(initial_metadata_key) |
|
|
|
|
fail AssertionError, "Expected initial metadata. None received" |
|
|
|
|
elsif op.metadata[initial_metadata_key] != metadata[initial_metadata_key] |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected initial metadata: #{metadata[initial_metadata_key]}. "\ |
|
|
|
|
"Received: #{op.metadata[initial_metadata_key]}" |
|
|
|
|
end |
|
|
|
|
if not op.trailing_metadata.has_key?(trailing_metadata_key) |
|
|
|
|
fail AssertionError, "Expected trailing metadata. None received" |
|
|
|
|
elsif op.trailing_metadata[trailing_metadata_key] != |
|
|
|
|
metadata[trailing_metadata_key] |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\ |
|
|
|
|
"Received: #{op.trailing_metadata[trailing_metadata_key]}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# Testing with FullDuplex |
|
|
|
|
req_cls, p_cls = StreamingOutputCallRequest, ResponseParameters |
|
|
|
|
duplex_req = req_cls.new(payload: Payload.new(body: nulls(1)), |
|
|
|
|
response_type: :COMPRESSABLE, |
|
|
|
|
response_parameters: [p_cls.new(size: 1)]) |
|
|
|
|
|
|
|
|
|
duplex_op = @stub.full_duplex_call([duplex_req], metadata: metadata, |
|
|
|
|
return_op: true) |
|
|
|
|
resp = duplex_op.execute |
|
|
|
|
resp.each { |r| } # ensures that the server sends trailing data |
|
|
|
|
duplex_op.wait |
|
|
|
|
if not duplex_op.metadata.has_key?(initial_metadata_key) |
|
|
|
|
fail AssertionError, "Expected initial metadata. None received" |
|
|
|
|
elsif duplex_op.metadata[initial_metadata_key] != |
|
|
|
|
metadata[initial_metadata_key] |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected initial metadata: #{metadata[initial_metadata_key]}. "\ |
|
|
|
|
"Received: #{duplex_op.metadata[initial_metadata_key]}" |
|
|
|
|
end |
|
|
|
|
if not duplex_op.trailing_metadata[trailing_metadata_key] |
|
|
|
|
fail AssertionError, "Expected trailing metadata. None received" |
|
|
|
|
elsif duplex_op.trailing_metadata[trailing_metadata_key] != |
|
|
|
|
metadata[trailing_metadata_key] |
|
|
|
|
fail AssertionError, |
|
|
|
|
"Expected trailing metadata: #{metadata[trailing_metadata_key]}. "\ |
|
|
|
|
"Received: #{duplex_op.trailing_metadata[trailing_metadata_key]}" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def all |
|
|
|
|
all_methods = NamedTests.instance_methods(false).map(&:to_s) |
|
|
|
|
all_methods.each do |m| |
|
|
|
|