|  | @@ -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)
 |