Corrects the handling of metadata when the optional deadline is specified
This commit is contained in:
parent
a42bd2705a
commit
77e2fb0f95
|
|
@ -176,25 +176,26 @@ module GRPC
|
|||
unmarshal = desc.unmarshal_proc(:output)
|
||||
route = "/#{route_prefix}/#{name}"
|
||||
if desc.request_response?
|
||||
define_method(mth_name) do |req, deadline = nil|
|
||||
define_method(mth_name) do |req, deadline = nil, **kw|
|
||||
logger.debug("calling #{@host}:#{route}")
|
||||
request_response(route, req, marshal, unmarshal, deadline)
|
||||
request_response(route, req, marshal, unmarshal, deadline, **kw)
|
||||
end
|
||||
elsif desc.client_streamer?
|
||||
define_method(mth_name) do |reqs, deadline = nil|
|
||||
define_method(mth_name) do |reqs, deadline = nil, **kw|
|
||||
logger.debug("calling #{@host}:#{route}")
|
||||
client_streamer(route, reqs, marshal, unmarshal, deadline)
|
||||
client_streamer(route, reqs, marshal, unmarshal, deadline, **kw)
|
||||
end
|
||||
elsif desc.server_streamer?
|
||||
define_method(mth_name) do |req, deadline = nil, &blk|
|
||||
define_method(mth_name) do |req, deadline = nil, **kw, &blk|
|
||||
logger.debug("calling #{@host}:#{route}")
|
||||
server_streamer(route, req, marshal, unmarshal, deadline,
|
||||
server_streamer(route, req, marshal, unmarshal, deadline, **kw,
|
||||
&blk)
|
||||
end
|
||||
else # is a bidi_stream
|
||||
define_method(mth_name) do |reqs, deadline = nil, &blk|
|
||||
define_method(mth_name) do |reqs, deadline = nil, **kw, &blk|
|
||||
logger.debug("calling #{@host}:#{route}")
|
||||
bidi_streamer(route, reqs, marshal, unmarshal, deadline, &blk)
|
||||
bidi_streamer(route, reqs, marshal, unmarshal, deadline, **kw,
|
||||
&blk)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -202,7 +203,7 @@ module GRPC
|
|||
end
|
||||
|
||||
# Asserts that the appropriate methods are defined for each added rpc
|
||||
# spec. Is intended to aid verifying that server classes are correctly
|
||||
# spec. Is intended to aid verifying that serve2Ar classes are correctly
|
||||
# implemented.
|
||||
def assert_rpc_descs_have_methods
|
||||
rpc_descs.each_pair do |m, spec|
|
||||
|
|
|
|||
|
|
@ -81,14 +81,17 @@ EchoStub = EchoService.rpc_stub_class
|
|||
class SlowService
|
||||
include GRPC::GenericService
|
||||
rpc :an_rpc, EchoMsg, EchoMsg
|
||||
attr_reader :received_md, :delay
|
||||
|
||||
def initialize(_default_var = 'ignored')
|
||||
@delay = 0.25
|
||||
@received_md = []
|
||||
end
|
||||
|
||||
def an_rpc(req, _call)
|
||||
delay = 0.25
|
||||
logger.info("starting a slow #{delay} rpc")
|
||||
sleep delay
|
||||
def an_rpc(req, call)
|
||||
logger.info("starting a slow #{@delay} rpc")
|
||||
sleep @delay
|
||||
@received_md << call.metadata unless call.metadata.nil?
|
||||
req # send back the req as the response
|
||||
end
|
||||
end
|
||||
|
|
@ -354,6 +357,37 @@ describe GRPC::RpcServer do
|
|||
t.join
|
||||
end
|
||||
|
||||
it 'should receive metadata when a deadline is specified', server: true do
|
||||
service = SlowService.new
|
||||
@srv.handle(service)
|
||||
t = Thread.new { @srv.run }
|
||||
@srv.wait_till_running
|
||||
req = EchoMsg.new
|
||||
stub = SlowStub.new(@host, **@client_opts)
|
||||
deadline = service.delay + 0.5 # wait for long enough
|
||||
expect(stub.an_rpc(req, deadline, k1: 'v1', k2: 'v2')).to be_a(EchoMsg)
|
||||
wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }]
|
||||
expect(service.received_md).to eq(wanted_md)
|
||||
@srv.stop
|
||||
t.join
|
||||
end
|
||||
|
||||
it 'should not receive metadata if the client times out', server: true do
|
||||
service = SlowService.new
|
||||
@srv.handle(service)
|
||||
t = Thread.new { @srv.run }
|
||||
@srv.wait_till_running
|
||||
req = EchoMsg.new
|
||||
stub = SlowStub.new(@host, **@client_opts)
|
||||
deadline = 0.1 # too short for SlowService to respond
|
||||
blk = proc { stub.an_rpc(req, deadline, k1: 'v1', k2: 'v2') }
|
||||
expect(&blk).to raise_error GRPC::BadStatus
|
||||
wanted_md = []
|
||||
expect(service.received_md).to eq(wanted_md)
|
||||
@srv.stop
|
||||
t.join
|
||||
end
|
||||
|
||||
it 'should receive updated metadata', server: true do
|
||||
service = EchoService.new
|
||||
@srv.handle(service)
|
||||
|
|
|
|||
Loading…
Reference in New Issue