diff options
author | Alex Polcyn <apolcyn@google.com> | 2016-07-31 19:08:56 -0700 |
---|---|---|
committer | Alex Polcyn <apolcyn@google.com> | 2016-10-26 09:58:19 -0700 |
commit | e5293c3f7b77c2ff7bef602e830e87794b12cdc2 (patch) | |
tree | 8d23648c3c8612a73963c7888a9994f8f27e322e /src/ruby/spec/generic | |
parent | 970078807f63726e32b30e1a263244a548d86e4c (diff) |
combine more core batch ops
Diffstat (limited to 'src/ruby/spec/generic')
-rw-r--r-- | src/ruby/spec/generic/active_call_spec.rb | 22 | ||||
-rw-r--r-- | src/ruby/spec/generic/client_stub_spec.rb | 123 | ||||
-rw-r--r-- | src/ruby/spec/generic/rpc_desc_spec.rb | 24 | ||||
-rw-r--r-- | src/ruby/spec/generic/rpc_server_spec.rb | 1 |
4 files changed, 117 insertions, 53 deletions
diff --git a/src/ruby/spec/generic/active_call_spec.rb b/src/ruby/spec/generic/active_call_spec.rb index 5ae4f25537..aa51d9d7b1 100644 --- a/src/ruby/spec/generic/active_call_spec.rb +++ b/src/ruby/spec/generic/active_call_spec.rb @@ -402,7 +402,7 @@ describe GRPC::ActiveCall do @pass_through, deadline) msg = 'message is a string' client_call.remote_send(msg) - client_call.writes_done(false) + call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil) server_call = expect_server_to_receive(msg) server_call.remote_send('server_response') server_call.send_status(OK, 'OK') @@ -460,7 +460,7 @@ describe GRPC::ActiveCall do msg = 'message is a string' reply = 'server_response' client_call.remote_send(msg) - client_call.writes_done(false) + call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil) server_call = expect_server_to_receive(msg) e = client_call.each_remote_read n = 3 # arbitrary value > 1 @@ -473,7 +473,7 @@ describe GRPC::ActiveCall do end end - describe '#writes_done' do + describe '#closing the call from the client' do it 'finishes ok if the server sends a status response' do call = make_test_call ActiveCall.client_invoke(call) @@ -481,7 +481,9 @@ describe GRPC::ActiveCall do @pass_through, deadline) msg = 'message is a string' client_call.remote_send(msg) - expect { client_call.writes_done(false) }.to_not raise_error + expect do + call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil) + end.to_not raise_error server_call = expect_server_to_receive(msg) server_call.remote_send('server_response') expect(client_call.remote_read).to eq('server_response') @@ -500,11 +502,13 @@ describe GRPC::ActiveCall do server_call.remote_send('server_response') server_call.send_status(OK, 'status code is OK') expect(client_call.remote_read).to eq('server_response') - expect { client_call.writes_done(false) }.to_not raise_error + expect do + call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil) + end.to_not raise_error expect { client_call.finished }.to_not raise_error end - it 'finishes ok if writes_done is true' do + it 'finishes ok if SEND_CLOSE and RECV_STATUS has been sent' do call = make_test_call ActiveCall.client_invoke(call) client_call = ActiveCall.new(call, @pass_through, @@ -515,7 +519,11 @@ describe GRPC::ActiveCall do server_call.remote_send('server_response') server_call.send_status(OK, 'status code is OK') expect(client_call.remote_read).to eq('server_response') - expect { client_call.writes_done(true) }.to_not raise_error + expect do + call.run_batch( + CallOps::SEND_CLOSE_FROM_CLIENT => nil, + CallOps::RECV_STATUS_ON_CLIENT => nil) + end.to_not raise_error end end diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb index 6034b5419c..e68b8db7ab 100644 --- a/src/ruby/spec/generic/client_stub_spec.rb +++ b/src/ruby/spec/generic/client_stub_spec.rb @@ -180,30 +180,44 @@ describe 'ClientStub' do end describe 'via a call operation' do - def get_response(stub) + def get_response(stub, run_start_call_first: false) op = stub.request_response(@method, @sent_msg, noop, noop, return_op: true, metadata: { k1: 'v1', k2: 'v2' }, deadline: from_relative_time(2)) expect(op).to be_a(GRPC::ActiveCall::Operation) - op.execute + op.start_call if run_start_call_first + result = op.execute + op.wait # make sure wait doesn't hang + result end it_behaves_like 'request response' - end - end - describe '#client_streamer' do - shared_examples 'client streaming' do - before(:each) do + it 'sends metadata to the server ok when running start_call first' do server_port = create_test_server host = "localhost:#{server_port}" - @stub = GRPC::ClientStub.new(host, :this_channel_is_insecure) - @metadata = { k1: 'v1', k2: 'v2' } - @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s } - @resp = 'a_reply' + th = run_request_response(@sent_msg, @resp, @pass, + k1: 'v1', k2: 'v2') + stub = GRPC::ClientStub.new(host, :this_channel_is_insecure) + expect(get_response(stub)).to eq(@resp) + th.join end + end + end + + describe '#client_streamer' do + before(:each) do + Thread.abort_on_exception = true + server_port = create_test_server + host = "localhost:#{server_port}" + @stub = GRPC::ClientStub.new(host, :this_channel_is_insecure) + @metadata = { k1: 'v1', k2: 'v2' } + @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s } + @resp = 'a_reply' + end + shared_examples 'client streaming' do it 'should send requests to/receive a reply from a server' do th = run_client_streamer(@sent_msgs, @resp, @pass) expect(get_response(@stub)).to eq(@resp) @@ -242,24 +256,33 @@ describe 'ClientStub' do end describe 'via a call operation' do - def get_response(stub) + def get_response(stub, run_start_call_first: false) op = stub.client_streamer(@method, @sent_msgs, noop, noop, return_op: true, metadata: @metadata) expect(op).to be_a(GRPC::ActiveCall::Operation) - op.execute + op.start_call if run_start_call_first + result = op.execute + op.wait # make sure wait doesn't hang + result end it_behaves_like 'client streaming' + + it 'sends metadata to the server ok when running start_call first' do + th = run_client_streamer(@sent_msgs, @resp, @pass, **@metadata) + expect(get_response(@stub, run_start_call_first: true)).to eq(@resp) + th.join + end end end describe '#server_streamer' do - shared_examples 'server streaming' do - before(:each) do - @sent_msg = 'a_msg' - @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s } - end + before(:each) do + @sent_msg = 'a_msg' + @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s } + end + shared_examples 'server streaming' do it 'should send a request to/receive replies from a server' do server_port = create_test_server host = "localhost:#{server_port}" @@ -303,29 +326,44 @@ describe 'ClientStub' do end describe 'via a call operation' do - def get_responses(stub) - op = stub.server_streamer(@method, @sent_msg, noop, noop, - return_op: true, - metadata: { k1: 'v1', k2: 'v2' }) - expect(op).to be_a(GRPC::ActiveCall::Operation) - e = op.execute + after(:each) do + @op.wait # make sure wait doesn't hang + end + def get_responses(stub, run_start_call_first: false) + @op = stub.server_streamer(@method, @sent_msg, noop, noop, + return_op: true, + metadata: { k1: 'v1', k2: 'v2' }) + expect(@op).to be_a(GRPC::ActiveCall::Operation) + @op.start_call if run_start_call_first + e = @op.execute expect(e).to be_a(Enumerator) e end it_behaves_like 'server streaming' + + it 'should send metadata to the server ok when start_call is run first' do + server_port = create_test_server + host = "localhost:#{server_port}" + th = run_server_streamer(@sent_msg, @replys, @fail, + k1: 'v1', k2: 'v2') + stub = GRPC::ClientStub.new(host, :this_channel_is_insecure) + e = get_responses(stub, run_start_call_first: true) + expect { e.collect { |r| r } }.to raise_error(GRPC::BadStatus) + th.join + end end end describe '#bidi_streamer' do - shared_examples 'bidi streaming' do - before(:each) do - @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s } - @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s } - server_port = create_test_server - @host = "localhost:#{server_port}" - end + before(:each) do + @sent_msgs = Array.new(3) { |i| 'msg_' + (i + 1).to_s } + @replys = Array.new(3) { |i| 'reply_' + (i + 1).to_s } + server_port = create_test_server + @host = "localhost:#{server_port}" + end + shared_examples 'bidi streaming' do it 'supports sending all the requests first', bidi: true do th = run_bidi_streamer_handle_inputs_first(@sent_msgs, @replys, @pass) @@ -363,16 +401,29 @@ describe 'ClientStub' do end describe 'via a call operation' do - def get_responses(stub) - op = stub.bidi_streamer(@method, @sent_msgs, noop, noop, - return_op: true) - expect(op).to be_a(GRPC::ActiveCall::Operation) - e = op.execute + after(:each) do + @op.wait # make sure wait doesn't hang + end + def get_responses(stub, run_start_call_first: false) + @op = stub.bidi_streamer(@method, @sent_msgs, noop, noop, + return_op: true) + expect(@op).to be_a(GRPC::ActiveCall::Operation) + @op.start_call if run_start_call_first + e = @op.execute expect(e).to be_a(Enumerator) e end it_behaves_like 'bidi streaming' + + it 'can run start_call before executing the call' do + th = run_bidi_streamer_handle_inputs_first(@sent_msgs, @replys, + @pass) + stub = GRPC::ClientStub.new(@host, :this_channel_is_insecure) + e = get_responses(stub, run_start_call_first: true) + expect(e.collect { |r| r }).to eq(@replys) + th.join + end end end diff --git a/src/ruby/spec/generic/rpc_desc_spec.rb b/src/ruby/spec/generic/rpc_desc_spec.rb index 1a895005bc..a3f0efa603 100644 --- a/src/ruby/spec/generic/rpc_desc_spec.rb +++ b/src/ruby/spec/generic/rpc_desc_spec.rb @@ -48,7 +48,7 @@ describe GRPC::RpcDesc do @bidi_streamer = RpcDesc.new('ss', Stream.new(Object.new), Stream.new(Object.new), 'encode', 'decode') @bs_code = INTERNAL - @no_reason = 'no reason given' + @no_reason = 'unkown error handling call on server' @ok_response = Object.new end @@ -83,6 +83,7 @@ describe GRPC::RpcDesc do before(:each) do @call = double('active_call') allow(@call).to receive(:single_req_view).and_return(@call) + allow(@call).to receive(:output_metadata).and_return(@call) end it_behaves_like 'it handles errors' @@ -90,10 +91,10 @@ describe GRPC::RpcDesc do it 'sends a response and closes the stream if there no errors' do req = Object.new expect(@call).to receive(:remote_read).once.and_return(req) - 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, - metadata: fake_md) + expect(@call).to receive(:output_metadata).once.and_return(fake_md) + expect(@call).to receive(:server_unary_response).once + .with(@ok_response, trailing_metadata: fake_md) + this_desc.run_server_method(@call, method(:fake_reqresp)) end end @@ -117,7 +118,9 @@ describe GRPC::RpcDesc do end it 'absorbs CallError with no further action' do - expect(@call).to receive(:remote_send).once.and_raise(CallError) + expect(@call).to receive(:server_unary_response).once.and_raise( + CallError) + allow(@call).to receive(:output_metadata).and_return({}) blk = proc do @client_streamer.run_server_method(@call, method(:fake_clstream)) end @@ -125,10 +128,11 @@ describe GRPC::RpcDesc do end it 'sends a response and closes the stream if there no errors' 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, - metadata: fake_md) + expect(@call).to receive(:output_metadata).and_return( + fake_md) + expect(@call).to receive(:server_unary_response).once + .with(@ok_response, trailing_metadata: fake_md) + @client_streamer.run_server_method(@call, method(:fake_clstream)) end end diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb index d362e48dee..c5694790fd 100644 --- a/src/ruby/spec/generic/rpc_server_spec.rb +++ b/src/ruby/spec/generic/rpc_server_spec.rb @@ -462,6 +462,7 @@ describe GRPC::RpcServer do 'connect_k1' => 'connect_v1' } wanted_md.each do |key, value| + puts "key: #{key}" expect(op.metadata[key]).to eq(value) end @srv.stop |