Merge pull request #1112 from tbetbetbe/grpc_ruby_fix_metadata_handling_when_deadline_specified

Grpc ruby fix metadata handling when deadline specified
pull/1115/head
Michael Lumish 10 years ago
commit f37bc1f259
  1. 17
      src/ruby/lib/grpc/generic/service.rb
  2. 4
      src/ruby/spec/generic/active_call_spec.rb
  3. 42
      src/ruby/spec/generic/rpc_server_spec.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

@ -67,7 +67,7 @@ describe GRPC::ActiveCall do
end
describe '#multi_req_view' do
xit 'exposes a fixed subset of the ActiveCall methods' do
it 'exposes a fixed subset of the ActiveCall methods' do
want = %w(cancelled, deadline, each_remote_read, metadata, shutdown)
v = @client_call.multi_req_view
want.each do |w|
@ -77,7 +77,7 @@ describe GRPC::ActiveCall do
end
describe '#single_req_view' do
xit 'exposes a fixed subset of the ActiveCall methods' do
it 'exposes a fixed subset of the ActiveCall methods' do
want = %w(cancelled, deadline, metadata, shutdown)
v = @client_call.single_req_view
want.each do |w|

@ -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…
Cancel
Save