diff options
author | Tim Emiola <temiola@google.com> | 2015-03-19 23:10:10 -0700 |
---|---|---|
committer | Tim Emiola <temiola@google.com> | 2015-03-23 12:29:21 -0700 |
commit | 77e2fb0f9521fd41f4e0ed3fc0d7dc5e9e4208ba (patch) | |
tree | 8c3424a470710027db24bad1701e83b2286e9f7d /src | |
parent | a42bd2705adfc2042274affb030aa877b58a538c (diff) |
Corrects the handling of metadata when the optional deadline is specified
Diffstat (limited to 'src')
-rw-r--r-- | src/ruby/lib/grpc/generic/service.rb | 19 | ||||
-rw-r--r-- | src/ruby/spec/generic/rpc_server_spec.rb | 42 |
2 files changed, 48 insertions, 13 deletions
diff --git a/src/ruby/lib/grpc/generic/service.rb b/src/ruby/lib/grpc/generic/service.rb index 6ea0831a2e..d128c3490d 100644 --- a/src/ruby/lib/grpc/generic/service.rb +++ b/src/ruby/lib/grpc/generic/service.rb @@ -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| diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb index f3b89b5895..34e5cdcd04 100644 --- a/src/ruby/spec/generic/rpc_server_spec.rb +++ b/src/ruby/spec/generic/rpc_server_spec.rb @@ -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) |