diff options
Diffstat (limited to 'src/ruby/spec')
-rw-r--r-- | src/ruby/spec/generic/rpc_server_pool_spec.rb | 4 | ||||
-rw-r--r-- | src/ruby/spec/generic/rpc_server_spec.rb | 42 |
2 files changed, 34 insertions, 12 deletions
diff --git a/src/ruby/spec/generic/rpc_server_pool_spec.rb b/src/ruby/spec/generic/rpc_server_pool_spec.rb index aae3a7d7cb..b67008de48 100644 --- a/src/ruby/spec/generic/rpc_server_pool_spec.rb +++ b/src/ruby/spec/generic/rpc_server_pool_spec.rb @@ -74,11 +74,11 @@ describe GRPC::Pool do end describe '#schedule' do - it 'throws if the pool is already stopped' do + it 'return if the pool is already stopped' do p = Pool.new(1) p.stop job = proc {} - expect { p.schedule(&job) }.to raise_error + expect { p.schedule(&job) }.to_not raise_error end it 'adds jobs that get run by the pool' do diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb index 640b0f656c..e60a8b27c3 100644 --- a/src/ruby/spec/generic/rpc_server_spec.rb +++ b/src/ruby/spec/generic/rpc_server_spec.rb @@ -212,10 +212,14 @@ describe GRPC::RpcServer do describe '#stopped?' do before(:each) do - opts = { a_channel_arg: 'an_arg', poll_period: 1 } + opts = { a_channel_arg: 'an_arg', poll_period: 1.5 } @srv = RpcServer.new(**opts) end + after(:each) do + @srv.stop + end + it 'starts out false' do expect(@srv.stopped?).to be(false) end @@ -225,7 +229,7 @@ describe GRPC::RpcServer do expect(@srv.stopped?).to be(false) end - it 'stays false after the server starts running' do + it 'stays false after the server starts running', server: true do @srv.handle(EchoService) t = Thread.new { @srv.run } @srv.wait_till_running @@ -234,7 +238,7 @@ describe GRPC::RpcServer do t.join end - it 'is true after a running server is stopped' do + it 'is true after a running server is stopped', server: true do @srv.handle(EchoService) t = Thread.new { @srv.run } @srv.wait_till_running @@ -251,21 +255,22 @@ describe GRPC::RpcServer do expect(r.running?).to be(false) end - it 'is false after run is called with no services registered' do + it 'is false if run is called with no services registered', server: true do opts = { a_channel_arg: 'an_arg', - poll_period: 1, + poll_period: 2, server_override: @server } r = RpcServer.new(**opts) r.run expect(r.running?).to be(false) + r.stop end it 'is true after run is called with a registered service' do opts = { a_channel_arg: 'an_arg', - poll_period: 1, + poll_period: 2.5, server_override: @server } r = RpcServer.new(**opts) @@ -284,6 +289,10 @@ describe GRPC::RpcServer do @srv = RpcServer.new(**@opts) end + after(:each) do + @srv.stop + end + it 'raises if #run has already been called' do @srv.handle(EchoService) t = Thread.new { @srv.run } @@ -335,6 +344,10 @@ describe GRPC::RpcServer do @srv = RpcServer.new(**server_opts) end + after(:each) do + @srv.stop + end + it 'should return NOT_FOUND status on unknown methods', server: true do @srv.handle(EchoService) t = Thread.new { @srv.run } @@ -376,7 +389,7 @@ describe GRPC::RpcServer do t.join end - it 'should receive metadata when a deadline is specified', server: true do + it 'should receive metadata if a deadline is specified', server: true do service = SlowService.new @srv.handle(service) t = Thread.new { @srv.run } @@ -445,11 +458,11 @@ describe GRPC::RpcServer do it 'should handle multiple parallel requests', server: true do @srv.handle(EchoService) - Thread.new { @srv.run } + t = Thread.new { @srv.run } @srv.wait_till_running req, q = EchoMsg.new, Queue.new n = 5 # arbitrary - threads = [] + threads = [t] n.times do threads << Thread.new do stub = EchoStub.new(@host, **client_opts) @@ -472,7 +485,7 @@ describe GRPC::RpcServer do } alt_srv = RpcServer.new(**opts) alt_srv.handle(SlowService) - Thread.new { alt_srv.run } + t = Thread.new { alt_srv.run } alt_srv.wait_till_running req = EchoMsg.new n = 5 # arbitrary, use as many to ensure the server pool is exceeded @@ -490,6 +503,7 @@ describe GRPC::RpcServer do end threads.each(&:join) alt_srv.stop + t.join expect(one_failed_as_unavailable).to be(true) end end @@ -513,6 +527,10 @@ describe GRPC::RpcServer do @srv = RpcServer.new(**server_opts) end + after(:each) do + @srv.stop + end + it 'should send connect metadata to the client', server: true do service = EchoService.new @srv.handle(service) @@ -545,6 +563,10 @@ describe GRPC::RpcServer do @srv = RpcServer.new(**server_opts) end + after(:each) do + @srv.stop + end + it 'should be added to BadStatus when requests fail', server: true do service = FailingService.new @srv.handle(service) |