Finished updating code and tests with keyword argument changes

pull/6662/head
murgatroid99 9 years ago
parent 83939ce3ac
commit ae34a370e3
  1. 2
      src/ruby/lib/grpc/generic/rpc_desc.rb
  2. 2
      src/ruby/lib/grpc/generic/rpc_server.rb
  3. 4
      src/ruby/spec/generic/active_call_spec.rb
  4. 15
      src/ruby/spec/generic/client_stub_spec.rb
  5. 22
      src/ruby/spec/generic/rpc_desc_spec.rb
  6. 55
      src/ruby/spec/generic/rpc_server_spec.rb
  7. 8
      src/ruby/spec/pb/health/checker_spec.rb

@ -138,7 +138,7 @@ module GRPC
def send_status(active_client, code, details, metadata = {})
details = 'Not sure why' if details.nil?
GRPC.logger.debug("Sending status #{code}:#{details}")
active_client.send_status(code, details, code == OK, metadata)
active_client.send_status(code, details, code == OK, metadata: metadata)
rescue StandardError => e
GRPC.logger.warn("Could not send status #{code}:#{details}")
GRPC.logger.warn(e)

@ -226,7 +226,7 @@ module GRPC
# running_state can take 4 values: :not_started, :running, :stopping, and
# :stopped. State transitions can only proceed in that order.
@running_state = :not_started
@server = Core::Server.new(cq, server_args)
@server = Core::Server.new(@cq, server_args)
end
# stops a running server

@ -161,8 +161,8 @@ describe GRPC::ActiveCall do
describe '#client_invoke' do
it 'sends metadata to the server when present' do
call = make_test_call
ActiveCall.client_invoke(call, @client_queue,
metadata: { k1: 'v1', k2: 'v2' })
metadata = { k1: 'v1', k2: 'v2' }
ActiveCall.client_invoke(call, @client_queue, metadata)
recvd_rpc = @server.request_call(@server_queue, @server_tag, deadline)
recvd_call = recvd_rpc.call
expect(recvd_call).to_not be_nil

@ -140,7 +140,7 @@ describe 'ClientStub' do
server_port = create_test_server
host = "localhost:#{server_port}"
th = run_request_response(@sent_msg, @resp, @pass,
metadata: { k1: 'v1', k2: 'v2' })
k1: 'v1', k2: 'v2')
stub = GRPC::ClientStub.new(host, @cq, :this_channel_is_insecure)
expect(get_response(stub)).to eq(@resp)
th.join
@ -197,7 +197,7 @@ describe 'ClientStub' do
server_port = create_test_server
host = "localhost:#{server_port}"
@stub = GRPC::ClientStub.new(host, @cq, :this_channel_is_insecure)
@options = { metadata: { k1: 'v1', k2: 'v2' } }
@metadata = { k1: 'v1', k2: 'v2' }
@sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s }
@resp = 'a_reply'
end
@ -209,7 +209,7 @@ describe 'ClientStub' do
end
it 'should send metadata to the server ok' do
th = run_client_streamer(@sent_msgs, @resp, @pass, **@options)
th = run_client_streamer(@sent_msgs, @resp, @pass, **@metadata)
expect(get_response(@stub)).to eq(@resp)
th.join
end
@ -222,7 +222,7 @@ describe 'ClientStub' do
end
it 'should raise ArgumentError if metadata contains invalid values' do
@options.merge!(k3: 3)
@metadata.merge!(k3: 3)
expect do
get_response(@stub)
end.to raise_error(ArgumentError,
@ -232,7 +232,8 @@ describe 'ClientStub' do
describe 'without a call operation' do
def get_response(stub)
stub.client_streamer(@method, @sent_msgs, noop, noop, **@options)
stub.client_streamer(@method, @sent_msgs, noop, noop,
metadata: @metadata)
end
it_behaves_like 'client streaming'
@ -241,7 +242,7 @@ describe 'ClientStub' do
describe 'via a call operation' do
def get_response(stub)
op = stub.client_streamer(@method, @sent_msgs, noop, noop,
return_op: true, **@options)
return_op: true, metadata: @metadata)
expect(op).to be_a(GRPC::ActiveCall::Operation)
op.execute
end
@ -291,7 +292,7 @@ describe 'ClientStub' do
describe 'without a call operation' do
def get_responses(stub)
e = stub.server_streamer(@method, @sent_msg, noop, noop,
k1: 'v1', k2: 'v2')
metadata: { k1: 'v1', k2: 'v2' })
expect(e).to be_a(Enumerator)
e
end

@ -56,14 +56,14 @@ describe GRPC::RpcDesc do
it 'sends the specified status if BadStatus is raised' do
expect(@call).to receive(:remote_read).once.and_return(Object.new)
expect(@call).to receive(:send_status).once.with(@bs_code, 'NOK', false,
{})
metadata: {})
this_desc.run_server_method(@call, method(:bad_status))
end
it 'sends status UNKNOWN if other StandardErrors are raised' do
expect(@call).to receive(:remote_read).once.and_return(Object.new)
expect(@call).to receive(:send_status) .once.with(UNKNOWN, @no_reason,
false, {})
false, metadata: {})
this_desc.run_server_method(@call, method(:other_error))
end
@ -93,7 +93,7 @@ describe GRPC::RpcDesc do
expect(@call).to receive(:remote_send).once.with(@ok_response)
expect(@call).to receive(:output_metadata).and_return(fake_md)
expect(@call).to receive(:send_status).once.with(OK, 'OK', true,
fake_md)
metadata: fake_md)
this_desc.run_server_method(@call, method(:fake_reqresp))
end
end
@ -106,13 +106,13 @@ describe GRPC::RpcDesc do
it 'sends the specified status if BadStatus is raised' do
expect(@call).to receive(:send_status).once.with(@bs_code, 'NOK', false,
{})
metadata: {})
@client_streamer.run_server_method(@call, method(:bad_status_alt))
end
it 'sends status UNKNOWN if other StandardErrors are raised' do
expect(@call).to receive(:send_status) .once.with(UNKNOWN, @no_reason,
false, {})
expect(@call).to receive(:send_status).once.with(UNKNOWN, @no_reason,
false, metadata: {})
@client_streamer.run_server_method(@call, method(:other_error_alt))
end
@ -128,7 +128,7 @@ describe GRPC::RpcDesc do
expect(@call).to receive(:remote_send).once.with(@ok_response)
expect(@call).to receive(:output_metadata).and_return(fake_md)
expect(@call).to receive(:send_status).once.with(OK, 'OK', true,
fake_md)
metadata: fake_md)
@client_streamer.run_server_method(@call, method(:fake_clstream))
end
end
@ -148,7 +148,7 @@ describe GRPC::RpcDesc do
expect(@call).to receive(:remote_send).twice.with(@ok_response)
expect(@call).to receive(:output_metadata).and_return(fake_md)
expect(@call).to receive(:send_status).once.with(OK, 'OK', true,
fake_md)
metadata: fake_md)
@server_streamer.run_server_method(@call, method(:fake_svstream))
end
end
@ -165,14 +165,14 @@ describe GRPC::RpcDesc do
e = GRPC::BadStatus.new(@bs_code, 'NOK')
expect(@call).to receive(:run_server_bidi).and_raise(e)
expect(@call).to receive(:send_status).once.with(@bs_code, 'NOK', false,
{})
metadata: {})
@bidi_streamer.run_server_method(@call, method(:bad_status_alt))
end
it 'sends status UNKNOWN if other StandardErrors are raised' do
expect(@call).to receive(:run_server_bidi).and_raise(StandardError)
expect(@call).to receive(:send_status).once.with(UNKNOWN, @no_reason,
false, {})
false, metadata: {})
@bidi_streamer.run_server_method(@call, method(:other_error_alt))
end
@ -180,7 +180,7 @@ describe GRPC::RpcDesc do
expect(@call).to receive(:run_server_bidi)
expect(@call).to receive(:output_metadata).and_return(fake_md)
expect(@call).to receive(:send_status).once.with(OK, 'OK', true,
fake_md)
metadata: fake_md)
@bidi_streamer.run_server_method(@call, method(:fake_bidistream))
end
end

@ -148,14 +148,6 @@ describe GRPC::RpcServer do
expect(&blk).not_to raise_error
end
it 'can be created with a default deadline' do
opts = { server_args: { a_channel_arg: 'an_arg' }, deadline: 5 }
blk = proc do
RpcServer.new(**opts)
end
expect(&blk).not_to raise_error
end
it 'can be created with a completion queue override' do
opts = {
server_args: { a_channel_arg: 'an_arg' },
@ -194,7 +186,7 @@ describe GRPC::RpcServer do
before(:each) do
opts = { server_args: { a_channel_arg: 'an_arg' }, poll_period: 1.5 }
@srv = RpcServer.new(**opts)
@srv.add_http2_port('0.0.0.0', :this_port_is_insecure)
@srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
end
it 'starts out false' do
@ -235,7 +227,7 @@ describe GRPC::RpcServer do
poll_period: 2
}
r = RpcServer.new(**opts)
r.add_http2_port('0.0.0.0', :this_port_is_insecure)
r.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
expect { r.run }.to raise_error(RuntimeError)
end
@ -245,7 +237,7 @@ describe GRPC::RpcServer do
poll_period: 2.5
}
r = RpcServer.new(**opts)
r.add_http2_port('0.0.0.0', :this_port_is_insecure)
r.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
r.handle(EchoService)
t = Thread.new { r.run }
r.wait_till_running
@ -257,9 +249,9 @@ describe GRPC::RpcServer do
describe '#handle' do
before(:each) do
@opts = { a_channel_arg: 'an_arg', poll_period: 1 }
@opts = { server_args: { a_channel_arg: 'an_arg' }, poll_period: 1 }
@srv = RpcServer.new(**@opts)
@srv.add_http2_port('0.0.0.0', :this_port_is_insecure)
@srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
end
it 'raises if #run has already been called' do
@ -306,7 +298,7 @@ describe GRPC::RpcServer do
poll_period: 1
}
@srv = RpcServer.new(**server_opts)
server_port = @srv.add_http2_port('0.0.0.0', :this_port_is_insecure)
server_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
@host = "localhost:#{server_port}"
@ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure)
end
@ -365,7 +357,8 @@ describe GRPC::RpcServer do
@srv.wait_till_running
req = EchoMsg.new
stub = EchoStub.new(@host, :this_channel_is_insecure, **client_opts)
expect(stub.an_rpc(req, k1: 'v1', k2: 'v2')).to be_a(EchoMsg)
expect(stub.an_rpc(req, metadata: { k1: 'v1', k2: 'v2' }))
.to be_a(EchoMsg)
wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }]
check_md(wanted_md, service.received_md)
@srv.stop
@ -379,8 +372,11 @@ describe GRPC::RpcServer do
@srv.wait_till_running
req = EchoMsg.new
stub = SlowStub.new(@host, :this_channel_is_insecure, **client_opts)
timeout = service.delay + 1.0 # wait for long enough
resp = stub.an_rpc(req, timeout: timeout, k1: 'v1', k2: 'v2')
timeout = service.delay + 1.0
deadline = GRPC::Core::TimeConsts.from_relative_time(timeout)
resp = stub.an_rpc(req,
deadline: deadline,
metadata: { k1: 'v1', k2: 'v2' })
expect(resp).to be_a(EchoMsg)
wanted_md = [{ 'k1' => 'v1', 'k2' => 'v2' }]
check_md(wanted_md, service.received_md)
@ -395,7 +391,7 @@ describe GRPC::RpcServer do
@srv.wait_till_running
req = EchoMsg.new
stub = SlowStub.new(@host, :this_channel_is_insecure, **client_opts)
op = stub.an_rpc(req, k1: 'v1', k2: 'v2', return_op: true)
op = stub.an_rpc(req, metadata: { k1: 'v1', k2: 'v2' }, return_op: true)
Thread.new do # cancel the call
sleep 0.1
op.cancel
@ -425,8 +421,7 @@ describe GRPC::RpcServer do
it 'should return RESOURCE_EXHAUSTED on too many jobs', server: true do
opts = {
a_channel_arg: 'an_arg',
server_override: @server,
server_args: { a_channel_arg: 'an_arg' },
completion_queue_override: @server_queue,
pool_size: 1,
poll_period: 1,
@ -434,6 +429,8 @@ describe GRPC::RpcServer do
}
alt_srv = RpcServer.new(**opts)
alt_srv.handle(SlowService)
alt_port = alt_srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
alt_host = "0.0.0.0:#{alt_port}"
t = Thread.new { alt_srv.run }
alt_srv.wait_till_running
req = EchoMsg.new
@ -442,7 +439,7 @@ describe GRPC::RpcServer do
one_failed_as_unavailable = false
n.times do
threads << Thread.new do
stub = SlowStub.new(@host, :this_channel_is_insecure, **client_opts)
stub = SlowStub.new(alt_host, :this_channel_is_insecure)
begin
stub.an_rpc(req)
rescue GRPC::BadStatus => e
@ -469,12 +466,13 @@ describe GRPC::RpcServer do
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)
alt_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
@alt_host = "0.0.0.0:#{alt_port}"
end
it 'should send connect metadata to the client', server: true do
@ -483,8 +481,8 @@ describe GRPC::RpcServer do
t = Thread.new { @srv.run }
@srv.wait_till_running
req = EchoMsg.new
stub = EchoStub.new(@host, :this_channel_is_insecure, **client_opts)
op = stub.an_rpc(req, k1: 'v1', k2: 'v2', return_op: true)
stub = EchoStub.new(@alt_host, :this_channel_is_insecure)
op = stub.an_rpc(req, metadata: { k1: 'v1', k2: 'v2' }, return_op: true)
expect(op.metadata).to be nil
expect(op.execute).to be_a(EchoMsg)
wanted_md = {
@ -504,11 +502,12 @@ describe GRPC::RpcServer do
context 'with trailing metadata' do
before(:each) do
server_opts = {
server_override: @server,
completion_queue_override: @server_queue,
poll_period: 1
}
@srv = RpcServer.new(**server_opts)
alt_port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
@alt_host = "0.0.0.0:#{alt_port}"
end
it 'should be added to BadStatus when requests fail', server: true do
@ -517,7 +516,7 @@ describe GRPC::RpcServer do
t = Thread.new { @srv.run }
@srv.wait_till_running
req = EchoMsg.new
stub = FailingStub.new(@host, :this_channel_is_insecure, **client_opts)
stub = FailingStub.new(@alt_host, :this_channel_is_insecure)
blk = proc { stub.an_rpc(req) }
# confirm it raise the expected error
@ -542,8 +541,8 @@ describe GRPC::RpcServer do
t = Thread.new { @srv.run }
@srv.wait_till_running
req = EchoMsg.new
stub = EchoStub.new(@host, :this_channel_is_insecure, **client_opts)
op = stub.an_rpc(req, k1: 'v1', k2: 'v2', return_op: true)
stub = EchoStub.new(@alt_host, :this_channel_is_insecure)
op = stub.an_rpc(req, return_op: true, metadata: { k1: 'v1', k2: 'v2' })
expect(op.metadata).to be nil
expect(op.execute).to be_a(EchoMsg)
expect(op.metadata).to eq(wanted_trailers)

@ -170,17 +170,15 @@ describe Grpc::Health::Checker do
before(:each) do
@server_queue = GRPC::Core::CompletionQueue.new
server_host = '0.0.0.0:0'
@server = GRPC::Core::Server.new(@server_queue, nil)
server_port = @server.add_http2_port(server_host, :this_port_is_insecure)
@host = "localhost:#{server_port}"
@ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure)
@client_opts = { channel_override: @ch }
server_opts = {
server_override: @server,
completion_queue_override: @server_queue,
poll_period: 1
}
@srv = RpcServer.new(**server_opts)
server_port = @srv.add_http2_port(server_host, :this_port_is_insecure)
@host = "localhost:#{server_port}"
@ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure)
end
after(:each) do

Loading…
Cancel
Save