|
|
|
@ -62,12 +62,15 @@ end |
|
|
|
|
class EchoService |
|
|
|
|
include GRPC::GenericService |
|
|
|
|
rpc :an_rpc, EchoMsg, EchoMsg |
|
|
|
|
attr_reader :received_md |
|
|
|
|
|
|
|
|
|
def initialize(_default_var = 'ignored') |
|
|
|
|
@received_md = [] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def an_rpc(req, _call) |
|
|
|
|
def an_rpc(req, call) |
|
|
|
|
logger.info('echo service received a request') |
|
|
|
|
@received_md << call.metadata unless call.metadata.nil? |
|
|
|
|
req |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
@ -337,6 +340,38 @@ describe GRPC::RpcServer do |
|
|
|
|
t.join |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should receive metadata sent as rpc keyword args', server: true do |
|
|
|
|
service = EchoService.new |
|
|
|
|
@srv.handle(service) |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
stub = EchoStub.new(@host, **@client_opts) |
|
|
|
|
expect(stub.an_rpc(req, 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 receive updated metadata', server: true do |
|
|
|
|
service = EchoService.new |
|
|
|
|
@srv.handle(service) |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
@client_opts[:update_metadata] = proc do |md| |
|
|
|
|
md[:k1] = 'updated-v1' |
|
|
|
|
md |
|
|
|
|
end |
|
|
|
|
stub = EchoStub.new(@host, **@client_opts) |
|
|
|
|
expect(stub.an_rpc(req, k1: 'v1', k2: 'v2')).to be_a(EchoMsg) |
|
|
|
|
wanted_md = [{ 'k1' => 'updated-v1', 'k2' => 'v2' }] |
|
|
|
|
expect(service.received_md).to eq(wanted_md) |
|
|
|
|
@srv.stop |
|
|
|
|
t.join |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should handle multiple parallel requests', server: true do |
|
|
|
|
@srv.handle(EchoService) |
|
|
|
|
Thread.new { @srv.run } |
|
|
|
|