|  | @@ -45,7 +45,7 @@ def wakey_thread(&blk)
 | 
	
		
			
				|  |  |  end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  def load_test_certs
 | 
	
		
			
				|  |  | -  test_root = File.join(File.parent(File.dirname(__FILE__)), 'testdata')
 | 
	
		
			
				|  |  | +  test_root = File.join(File.dirname(File.dirname(__FILE__)), 'testdata')
 | 
	
		
			
				|  |  |    files = ['ca.pem', 'server1.key', 'server1.pem']
 | 
	
		
			
				|  |  |    files.map { |f| File.open(File.join(test_root, f)).read }
 | 
	
		
			
				|  |  |  end
 | 
	
	
		
			
				|  | @@ -136,14 +136,32 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |        @sent_msg, @resp = 'a_msg', 'a_reply'
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'without a call operation' do
 | 
	
		
			
				|  |  | +    shared_examples 'request response' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'should send a request to/receive a_reply from a server' do
 | 
	
		
			
				|  |  | +      it 'should send a request to/receive a reply from a server' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_request_response(host, @sent_msg, @resp, @pass)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        resp = stub.request_response(@method, @sent_msg, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(resp).to eq(@resp)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  | +        th.join
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      it 'should send metadata to the server ok' do
 | 
	
		
			
				|  |  | +        host = new_test_host
 | 
	
		
			
				|  |  | +        th = run_request_response(host, @sent_msg, @resp, @pass, k1: 'v1',
 | 
	
		
			
				|  |  | +                                  k2: 'v2')
 | 
	
		
			
				|  |  | +        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  | +        th.join
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      it 'should update the sent metadata with a provided metadata updater' do
 | 
	
		
			
				|  |  | +        host = new_test_host
 | 
	
		
			
				|  |  | +        th = run_request_response(host, @sent_msg, @resp, @pass,
 | 
	
		
			
				|  |  | +                                  k1: 'updated-v1', k2: 'v2')
 | 
	
		
			
				|  |  | +        update_md = Proc.new { |md| md[:k1] = 'updated-v1'; md }
 | 
	
		
			
				|  |  | +        stub = GRPC::ClientStub.new(host, @cq, update_metadata: update_md)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -151,10 +169,8 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |          alt_host = new_test_host
 | 
	
		
			
				|  |  |          th = run_request_response(alt_host, @sent_msg, @resp, @pass)
 | 
	
		
			
				|  |  |          ch = GRPC::Core::Channel.new(alt_host, nil)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new('ignored-host', @cq,
 | 
	
		
			
				|  |  | -                                    channel_override:ch)
 | 
	
		
			
				|  |  | -        resp = stub.request_response(@method, @sent_msg, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(resp).to eq(@resp)
 | 
	
		
			
				|  |  | +        stub = GRPC::ClientStub.new('ignored-host', @cq, channel_override:ch)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -162,89 +178,73 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_request_response(host, @sent_msg, @resp, @fail)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        blk = Proc.new do
 | 
	
		
			
				|  |  | -          stub.request_response(@method, @sent_msg, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        end
 | 
	
		
			
				|  |  | +        blk = Proc.new { get_response(stub) }
 | 
	
		
			
				|  |  |          expect(&blk).to raise_error(GRPC::BadStatus)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'via a call operation' do
 | 
	
		
			
				|  |  | +    describe 'without a call operation' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'should send a request to/receive a_reply from a server' do
 | 
	
		
			
				|  |  | -        host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_request_response(host, @sent_msg, @resp, @pass)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        op = stub.request_response(@method, @sent_msg, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                   return_op:true)
 | 
	
		
			
				|  |  | -        expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        resp = op.execute()
 | 
	
		
			
				|  |  | -        expect(resp).to eq(@resp)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | +      def get_response(stub)
 | 
	
		
			
				|  |  | +        stub.request_response(@method, @sent_msg, NOOP, NOOP, k1: 'v1',
 | 
	
		
			
				|  |  | +                              k2: 'v2')
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'should raise an error if the status is not OK' do
 | 
	
		
			
				|  |  | -        host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_request_response(host, @sent_msg, @resp, @fail)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | +      it_behaves_like 'request response'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    describe 'via a call operation' do
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      def get_response(stub)
 | 
	
		
			
				|  |  |          op = stub.request_response(@method, @sent_msg, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                   return_op:true)
 | 
	
		
			
				|  |  | +                                   return_op:true, k1: 'v1', k2: 'v2')
 | 
	
		
			
				|  |  |          expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        blk = Proc.new do
 | 
	
		
			
				|  |  | -          op.execute()
 | 
	
		
			
				|  |  | -        end
 | 
	
		
			
				|  |  | -        expect(&blk).to raise_error(GRPC::BadStatus)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | +        op.execute()
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +      it_behaves_like 'request response'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    describe '#client_streamer' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    before(:each) do
 | 
	
		
			
				|  |  | -      @sent_msgs = Array.new(3) { |i| 'msg_' + (i+1).to_s }
 | 
	
		
			
				|  |  | -      @resp = 'a_reply'
 | 
	
		
			
				|  |  | -    end
 | 
	
		
			
				|  |  | +    shared_examples 'client streaming' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'without a call operation' do
 | 
	
		
			
				|  |  | +      before(:each) do
 | 
	
		
			
				|  |  | +        @sent_msgs = Array.new(3) { |i| 'msg_' + (i+1).to_s }
 | 
	
		
			
				|  |  | +        @resp = 'a_reply'
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        it 'should send requests to/receive a reply from a server' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_client_streamer(host, @sent_msgs, @resp, @pass)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        resp = stub.client_streamer(@method, @sent_msgs, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(resp).to eq(@resp)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'should raise an error if the status is not ok' do
 | 
	
		
			
				|  |  | +      it 'should send metadata to the server ok' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_client_streamer(host, @sent_msgs, @resp, @fail)
 | 
	
		
			
				|  |  | +        th = run_client_streamer(host, @sent_msgs, @resp, @pass, k1: 'v1',
 | 
	
		
			
				|  |  | +                                 k2: 'v2')
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        blk = Proc.new do
 | 
	
		
			
				|  |  | -          stub.client_streamer(@method, @sent_msgs, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        end
 | 
	
		
			
				|  |  | -        expect(&blk).to raise_error(BadStatus)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'via a call operation' do
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -      it 'should send requests to/receive a reply from a server' do
 | 
	
		
			
				|  |  | +      it 'should update the sent metadata with a provided metadata updater' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_client_streamer(host, @sent_msgs, @resp, @pass)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        op = stub.client_streamer(@method, @sent_msgs, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                  return_op:true)
 | 
	
		
			
				|  |  | -        expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        resp = op.execute()
 | 
	
		
			
				|  |  | -        expect(resp).to eq(@resp)
 | 
	
		
			
				|  |  | +        th = run_client_streamer(host, @sent_msgs, @resp, @pass,
 | 
	
		
			
				|  |  | +                                 k1: 'updated-v1', k2: 'v2')
 | 
	
		
			
				|  |  | +        update_md = Proc.new { |md| md[:k1] = 'updated-v1'; md }
 | 
	
		
			
				|  |  | +        stub = GRPC::ClientStub.new(host, @cq, update_metadata: update_md)
 | 
	
		
			
				|  |  | +        expect(get_response(stub)).to eq(@resp)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -252,36 +252,53 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_client_streamer(host, @sent_msgs, @resp, @fail)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | +        blk = Proc.new { get_response(stub) }
 | 
	
		
			
				|  |  | +        expect(&blk).to raise_error(GRPC::BadStatus)
 | 
	
		
			
				|  |  | +        th.join
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    describe 'without a call operation' do
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      def get_response(stub)
 | 
	
		
			
				|  |  | +        stub.client_streamer(@method, @sent_msgs, NOOP, NOOP, k1: 'v1',
 | 
	
		
			
				|  |  | +                             k2: 'v2')
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      it_behaves_like 'client streaming'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    describe 'via a call operation' do
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      def get_response(stub)
 | 
	
		
			
				|  |  |          op = stub.client_streamer(@method, @sent_msgs, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                  return_op:true)
 | 
	
		
			
				|  |  | +                                  return_op:true, k1: 'v1', k2: 'v2')
 | 
	
		
			
				|  |  |          expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        blk = Proc.new do
 | 
	
		
			
				|  |  | -          op.execute()
 | 
	
		
			
				|  |  | -        end
 | 
	
		
			
				|  |  | -        expect(&blk).to raise_error(BadStatus)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | +        resp = op.execute()
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +      it_behaves_like 'client streaming'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    describe '#server_streamer' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    before(:each) do
 | 
	
		
			
				|  |  | -      @sent_msg = 'a_msg'
 | 
	
		
			
				|  |  | -      @replys = Array.new(3) { |i| 'reply_' + (i+1).to_s }
 | 
	
		
			
				|  |  | -    end
 | 
	
		
			
				|  |  | +    shared_examples 'server streaming' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'without a call operation' do
 | 
	
		
			
				|  |  | +      before(:each) do
 | 
	
		
			
				|  |  | +        @sent_msg = 'a_msg'
 | 
	
		
			
				|  |  | +        @replys = Array.new(3) { |i| 'reply_' + (i+1).to_s }
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        it 'should send a request to/receive replies from a server' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_server_streamer(host, @sent_msg, @replys, @pass)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        e = stub.server_streamer(@method, @sent_msg, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | -        expect(e.collect { |r| r }).to eq(@replys)
 | 
	
		
			
				|  |  | +        expect(get_responses(stub).collect { |r| r }).to eq(@replys)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -289,60 +306,79 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_server_streamer(host, @sent_msg, @replys, @fail)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        e = stub.server_streamer(@method, @sent_msg, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | -        expect { e.collect { |r| r } }.to raise_error(BadStatus)
 | 
	
		
			
				|  |  | +        e = get_responses(stub)
 | 
	
		
			
				|  |  | +        expect { e.collect { |r| r } }.to raise_error(GRPC::BadStatus)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    end
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    describe 'via a call operation' do
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -      it 'should send a request to/receive replies from a server' do
 | 
	
		
			
				|  |  | +      it 'should send metadata to the server ok' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_server_streamer(host, @sent_msg, @replys, @pass)
 | 
	
		
			
				|  |  | +        th = run_server_streamer(host, @sent_msg, @replys, @fail, k1: 'v1',
 | 
	
		
			
				|  |  | +                                 k2: 'v2')
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        op = stub.server_streamer(@method, @sent_msg, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                  return_op:true)
 | 
	
		
			
				|  |  | -        expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        e = op.execute()
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | +        e = get_responses(stub)
 | 
	
		
			
				|  |  | +        expect { e.collect { |r| r } }.to raise_error(GRPC::BadStatus)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'should raise an error if the status is not ok' do
 | 
	
		
			
				|  |  | +      it 'should update the sent metadata with a provided metadata updater' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_server_streamer(host, @sent_msg, @replys, @fail)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | +        th = run_server_streamer(host, @sent_msg, @replys, @pass,
 | 
	
		
			
				|  |  | +                                 k1: 'updated-v1', k2: 'v2')
 | 
	
		
			
				|  |  | +        update_md = Proc.new { |md| md[:k1] = 'updated-v1'; md }
 | 
	
		
			
				|  |  | +        stub = GRPC::ClientStub.new(host, @cq, update_metadata: update_md)
 | 
	
		
			
				|  |  | +        e = get_responses(stub)
 | 
	
		
			
				|  |  | +        expect(e.collect { |r| r }).to eq(@replys)
 | 
	
		
			
				|  |  | +        th.join
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    describe 'without a call operation' do
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      def get_responses(stub)
 | 
	
		
			
				|  |  | +        e = stub.server_streamer(@method, @sent_msg, NOOP, NOOP, k1: 'v1',
 | 
	
		
			
				|  |  | +                                 k2: 'v2')
 | 
	
		
			
				|  |  | +        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | +        e
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      it_behaves_like 'server streaming'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    end
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    describe 'via a call operation' do
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      def get_responses(stub)
 | 
	
		
			
				|  |  |          op = stub.server_streamer(@method, @sent_msg, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                  return_op:true)
 | 
	
		
			
				|  |  | +                                  return_op:true, k1: 'v1', k2: 'v2')
 | 
	
		
			
				|  |  |          expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  |          e = op.execute()
 | 
	
		
			
				|  |  |          expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | -        expect { e.collect { |r| r } }.to raise_error(BadStatus)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | +        e
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +      it_behaves_like 'server streaming'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    describe '#bidi_streamer' 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 }
 | 
	
		
			
				|  |  | -    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'without a call operation' 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 }
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        it 'supports sending all the requests first', :bidi => true do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_bidi_streamer_handle_inputs_first(host, @sent_msgs, @replys,
 | 
	
		
			
				|  |  |                                                     @pass)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        e = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | +        e = get_responses(stub)
 | 
	
		
			
				|  |  |          expect(e.collect { |r| r }).to eq(@replys)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
	
		
			
				|  | @@ -351,8 +387,7 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_bidi_streamer_echo_ping_pong(host, @sent_msgs, @pass, true)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        e = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | +        e = get_responses(stub)
 | 
	
		
			
				|  |  |          expect(e.collect { |r| r }).to eq(@sent_msgs)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
	
		
			
				|  | @@ -367,68 +402,48 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |          host = new_test_host
 | 
	
		
			
				|  |  |          th = run_bidi_streamer_echo_ping_pong(host, @sent_msgs, @pass, false)
 | 
	
		
			
				|  |  |          stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        e = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP)
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | +        e = get_responses(stub)
 | 
	
		
			
				|  |  |          expect(e.collect { |r| r }).to eq(@sent_msgs)
 | 
	
		
			
				|  |  |          th.join
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    describe 'via a call operation' do
 | 
	
		
			
				|  |  | +    describe 'without a call operation' do
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'supports sending all the requests first', :bidi => true do
 | 
	
		
			
				|  |  | -        host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_bidi_streamer_handle_inputs_first(host, @sent_msgs, @replys,
 | 
	
		
			
				|  |  | -                                                   @pass)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        op = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                return_op:true)
 | 
	
		
			
				|  |  | -        expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        e = op.execute
 | 
	
		
			
				|  |  | +      def get_responses(stub)
 | 
	
		
			
				|  |  | +        e = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP)
 | 
	
		
			
				|  |  |          expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | -        expect(e.collect { |r| r }).to eq(@replys)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | +        e
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      it 'supports client-initiated ping pong', :bidi => true  do
 | 
	
		
			
				|  |  | -        host = new_test_host
 | 
	
		
			
				|  |  | -        th = run_bidi_streamer_echo_ping_pong(host, @sent_msgs, @pass, true)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        op = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                return_op:true)
 | 
	
		
			
				|  |  | -        expect(op).to be_a(GRPC::ActiveCall::Operation)
 | 
	
		
			
				|  |  | -        e = op.execute
 | 
	
		
			
				|  |  | -        expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | -        expect(e.collect { |r| r }).to eq(@sent_msgs)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | -      end
 | 
	
		
			
				|  |  | +      it_behaves_like 'bidi streaming'
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -      # disabled because an unresolved wire-protocol implementation feature
 | 
	
		
			
				|  |  | -      #
 | 
	
		
			
				|  |  | -      # - servers should be able initiate messaging, however, as it stand
 | 
	
		
			
				|  |  | -      # servers don't know if all the client metadata has been sent until
 | 
	
		
			
				|  |  | -      # they receive a message from the client.  Without receiving all the
 | 
	
		
			
				|  |  | -      # metadata, the server does not accept the call, so this test hangs.
 | 
	
		
			
				|  |  | -      xit 'supports server-initiated ping pong', :bidi => true do
 | 
	
		
			
				|  |  | -        th = run_bidi_streamer_echo_ping_pong(host, @sent_msgs, @pass, false)
 | 
	
		
			
				|  |  | -        stub = GRPC::ClientStub.new(host, @cq)
 | 
	
		
			
				|  |  | -        op = stub.bidi_streamer(@method, @sent_msgs, NOOP, NOOP,
 | 
	
		
			
				|  |  | -                                return_op:true)
 | 
	
		
			
				|  |  | +    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
 | 
	
		
			
				|  |  |          expect(e).to be_a(Enumerator)
 | 
	
		
			
				|  |  | -        expect(e.collect { |r| r }).to eq(@sent_msgs)
 | 
	
		
			
				|  |  | -        th.join
 | 
	
		
			
				|  |  | +        e
 | 
	
		
			
				|  |  |        end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +      it_behaves_like 'bidi streaming'
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  def run_server_streamer(hostname, expected_input, replys, status)
 | 
	
		
			
				|  |  | +  def run_server_streamer(hostname, expected_input, replys, status, **kw)
 | 
	
		
			
				|  |  | +    wanted_metadata = kw.clone
 | 
	
		
			
				|  |  |      wakey_thread do |mtx, cnd|
 | 
	
		
			
				|  |  |        c = expect_server_to_be_invoked(hostname, mtx, cnd)
 | 
	
		
			
				|  |  | +      wanted_metadata.each do |k, v|
 | 
	
		
			
				|  |  | +        expect(c.metadata[k.to_s]).to eq(v)
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  |        expect(c.remote_read).to eq(expected_input)
 | 
	
		
			
				|  |  |        replys.each { |r| c.remote_send(r) }
 | 
	
		
			
				|  |  |        c.send_status(status, status == @pass ? 'OK' : 'NOK', true)
 | 
	
	
		
			
				|  | @@ -462,19 +477,27 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  def run_client_streamer(hostname, expected_inputs, resp, status)
 | 
	
		
			
				|  |  | +  def run_client_streamer(hostname, expected_inputs, resp, status, **kw)
 | 
	
		
			
				|  |  | +    wanted_metadata = kw.clone
 | 
	
		
			
				|  |  |      wakey_thread do |mtx, cnd|
 | 
	
		
			
				|  |  |        c = expect_server_to_be_invoked(hostname, mtx, cnd)
 | 
	
		
			
				|  |  |        expected_inputs.each { |i| expect(c.remote_read).to eq(i) }
 | 
	
		
			
				|  |  | +      wanted_metadata.each do |k, v|
 | 
	
		
			
				|  |  | +        expect(c.metadata[k.to_s]).to eq(v)
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  |        c.remote_send(resp)
 | 
	
		
			
				|  |  |        c.send_status(status, status == @pass ? 'OK' : 'NOK', true)
 | 
	
		
			
				|  |  |      end
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  def run_request_response(hostname, expected_input, resp, status)
 | 
	
		
			
				|  |  | +  def run_request_response(hostname, expected_input, resp, status, **kw)
 | 
	
		
			
				|  |  | +    wanted_metadata = kw.clone
 | 
	
		
			
				|  |  |      wakey_thread do |mtx, cnd|
 | 
	
		
			
				|  |  |        c = expect_server_to_be_invoked(hostname, mtx, cnd)
 | 
	
		
			
				|  |  |        expect(c.remote_read).to eq(expected_input)
 | 
	
		
			
				|  |  | +      wanted_metadata.each do |k, v|
 | 
	
		
			
				|  |  | +        expect(c.metadata[k.to_s]).to eq(v)
 | 
	
		
			
				|  |  | +      end
 | 
	
		
			
				|  |  |        c.remote_send(resp)
 | 
	
		
			
				|  |  |        c.send_status(status, status == @pass ? 'OK' : 'NOK', true)
 | 
	
		
			
				|  |  |      end
 | 
	
	
		
			
				|  | @@ -496,9 +519,11 @@ describe 'ClientStub' do
 | 
	
		
			
				|  |  |      test_deadline = Time.now + 10  # fail tests after 10 seconds
 | 
	
		
			
				|  |  |      ev = server_queue.pluck(@server_tag, INFINITE_FUTURE)
 | 
	
		
			
				|  |  |      raise OutOfTime if ev.nil?
 | 
	
		
			
				|  |  | +    server_call = ev.call
 | 
	
		
			
				|  |  | +    server_call.metadata = ev.result.metadata
 | 
	
		
			
				|  |  |      finished_tag = Object.new
 | 
	
		
			
				|  |  | -    ev.call.accept(server_queue, finished_tag)
 | 
	
		
			
				|  |  | -    GRPC::ActiveCall.new(ev.call, server_queue, NOOP, NOOP, INFINITE_FUTURE,
 | 
	
		
			
				|  |  | +    server_call.accept(server_queue, finished_tag)
 | 
	
		
			
				|  |  | +    GRPC::ActiveCall.new(server_call, server_queue, NOOP, NOOP, INFINITE_FUTURE,
 | 
	
		
			
				|  |  |                           finished_tag: finished_tag)
 | 
	
		
			
				|  |  |    end
 | 
	
		
			
				|  |  |  
 |