|
|
|
@ -301,21 +301,20 @@ describe GRPC::RpcServer do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe '#run' do |
|
|
|
|
before(:each) do |
|
|
|
|
@client_opts = { |
|
|
|
|
channel_override: @ch |
|
|
|
|
} |
|
|
|
|
@marshal = EchoService.rpc_descs[:an_rpc].marshal_proc |
|
|
|
|
@unmarshal = EchoService.rpc_descs[:an_rpc].unmarshal_proc(:output) |
|
|
|
|
server_opts = { |
|
|
|
|
server_override: @server, |
|
|
|
|
completion_queue_override: @server_queue, |
|
|
|
|
poll_period: 1 |
|
|
|
|
} |
|
|
|
|
@srv = RpcServer.new(**server_opts) |
|
|
|
|
end |
|
|
|
|
let(:client_opts) { { channel_override: @ch } } |
|
|
|
|
let(:marshal) { EchoService.rpc_descs[:an_rpc].marshal_proc } |
|
|
|
|
let(:unmarshal) { EchoService.rpc_descs[:an_rpc].unmarshal_proc(:output) } |
|
|
|
|
|
|
|
|
|
context 'with no connect_metadata' do |
|
|
|
|
before(:each) do |
|
|
|
|
server_opts = { |
|
|
|
|
server_override: @server, |
|
|
|
|
completion_queue_override: @server_queue, |
|
|
|
|
poll_period: 1 |
|
|
|
|
} |
|
|
|
|
@srv = RpcServer.new(**server_opts) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'when running' do |
|
|
|
|
it 'should return NOT_FOUND status on unknown methods', server: true do |
|
|
|
|
@srv.handle(EchoService) |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
@ -323,8 +322,8 @@ describe GRPC::RpcServer do |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
blk = proc do |
|
|
|
|
cq = GRPC::Core::CompletionQueue.new |
|
|
|
|
stub = GRPC::ClientStub.new(@host, cq, **@client_opts) |
|
|
|
|
stub.request_response('/unknown', req, @marshal, @unmarshal) |
|
|
|
|
stub = GRPC::ClientStub.new(@host, cq, **client_opts) |
|
|
|
|
stub.request_response('/unknown', req, marshal, unmarshal) |
|
|
|
|
end |
|
|
|
|
expect(&blk).to raise_error GRPC::BadStatus |
|
|
|
|
@srv.stop |
|
|
|
@ -337,7 +336,7 @@ describe GRPC::RpcServer do |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
n = 5 # arbitrary |
|
|
|
|
stub = EchoStub.new(@host, **@client_opts) |
|
|
|
|
stub = EchoStub.new(@host, **client_opts) |
|
|
|
|
n.times { expect(stub.an_rpc(req)).to be_a(EchoMsg) } |
|
|
|
|
@srv.stop |
|
|
|
|
t.join |
|
|
|
@ -349,7 +348,7 @@ describe GRPC::RpcServer do |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
stub = EchoStub.new(@host, **@client_opts) |
|
|
|
|
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) |
|
|
|
@ -363,7 +362,7 @@ describe GRPC::RpcServer do |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
stub = SlowStub.new(@host, **@client_opts) |
|
|
|
|
stub = SlowStub.new(@host, **client_opts) |
|
|
|
|
deadline = service.delay + 1.0 # wait for long enough |
|
|
|
|
expect(stub.an_rpc(req, deadline, k1: 'v1', k2: 'v2')).to be_a(EchoMsg) |
|
|
|
|
wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }] |
|
|
|
@ -378,7 +377,7 @@ describe GRPC::RpcServer do |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
stub = SlowStub.new(@host, **@client_opts) |
|
|
|
|
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 |
|
|
|
@ -394,7 +393,7 @@ describe GRPC::RpcServer do |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
stub = SlowStub.new(@host, **@client_opts) |
|
|
|
|
stub = SlowStub.new(@host, **client_opts) |
|
|
|
|
op = stub.an_rpc(req, k1: 'v1', k2: 'v2', return_op: true) |
|
|
|
|
Thread.new do # cancel the call |
|
|
|
|
sleep 0.1 |
|
|
|
@ -411,11 +410,11 @@ describe GRPC::RpcServer do |
|
|
|
|
t = Thread.new { @srv.run } |
|
|
|
|
@srv.wait_till_running |
|
|
|
|
req = EchoMsg.new |
|
|
|
|
@client_opts[:update_metadata] = proc do |md| |
|
|
|
|
client_opts[:update_metadata] = proc do |md| |
|
|
|
|
md[:k1] = 'updated-v1' |
|
|
|
|
md |
|
|
|
|
end |
|
|
|
|
stub = EchoStub.new(@host, **@client_opts) |
|
|
|
|
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', |
|
|
|
|
'jwt_aud_uri' => "https://#{@host}/EchoService" }] |
|
|
|
@ -433,7 +432,7 @@ describe GRPC::RpcServer do |
|
|
|
|
threads = [] |
|
|
|
|
n.times do |
|
|
|
|
threads << Thread.new do |
|
|
|
|
stub = EchoStub.new(@host, **@client_opts) |
|
|
|
|
stub = EchoStub.new(@host, **client_opts) |
|
|
|
|
q << stub.an_rpc(req) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
@ -461,7 +460,7 @@ describe GRPC::RpcServer do |
|
|
|
|
one_failed_as_unavailable = false |
|
|
|
|
n.times do |
|
|
|
|
threads << Thread.new do |
|
|
|
|
stub = SlowStub.new(@host, **@client_opts) |
|
|
|
|
stub = SlowStub.new(@host, **client_opts) |
|
|
|
|
begin |
|
|
|
|
stub.an_rpc(req) |
|
|
|
|
rescue GRPC::BadStatus => e |
|
|
|
@ -474,5 +473,46 @@ describe GRPC::RpcServer do |
|
|
|
|
expect(one_failed_as_unavailable).to be(true) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with connect metadata' do |
|
|
|
|
let(:test_md_proc) do |
|
|
|
|
proc do |mth, md| |
|
|
|
|
res = md.clone |
|
|
|
|
res['method'] = mth |
|
|
|
|
res['connect_k1'] = 'connect_v1' |
|
|
|
|
res |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
before(:each) do |
|
|
|
|
server_opts = { |
|
|
|
|
server_override: @server, |
|
|
|
|
completion_queue_override: @server_queue, |
|
|
|
|
poll_period: 1, |
|
|
|
|
connect_md_proc: test_md_proc |
|
|
|
|
} |
|
|
|
|
@srv = RpcServer.new(**server_opts) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'should send connect metadata to the client', 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) |
|
|
|
|
op = stub.an_rpc(req, k1: 'v1', k2: 'v2', return_op: true) |
|
|
|
|
expect(op.metadata).to be nil |
|
|
|
|
expect(op.execute).to be_a(EchoMsg) |
|
|
|
|
wanted_md = { |
|
|
|
|
'k1' => 'v1', |
|
|
|
|
'k2' => 'v2', |
|
|
|
|
'method' => '/EchoService/an_rpc', |
|
|
|
|
'connect_k1' => 'connect_v1' |
|
|
|
|
} |
|
|
|
|
expect(op.metadata).to eq(wanted_md) |
|
|
|
|
@srv.stop |
|
|
|
|
t.join |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|