aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/spec
diff options
context:
space:
mode:
authorGravatar Alexander Polcyn <apolcyn@google.com>2017-12-13 14:43:24 -0800
committerGravatar Alexander Polcyn <apolcyn@google.com>2017-12-13 16:43:00 -0800
commitb14f1ea60208013b236ebd2f9a2601afb7bdeaf9 (patch)
tree6baca4b6c4f4629acd14c66ac368c98d1c509a74 /src/ruby/spec
parenta81ff04cc9d5f5525f5350db747d9249f177fdd4 (diff)
Disable soreuseport in ruby unit tests
Diffstat (limited to 'src/ruby/spec')
-rw-r--r--src/ruby/spec/channel_connection_spec.rb3
-rw-r--r--src/ruby/spec/client_auth_spec.rb2
-rw-r--r--src/ruby/spec/client_server_spec.rb4
-rw-r--r--src/ruby/spec/generic/active_call_spec.rb2
-rw-r--r--src/ruby/spec/generic/client_stub_spec.rb4
-rw-r--r--src/ruby/spec/generic/interceptor_registry_spec.rb2
-rw-r--r--src/ruby/spec/generic/rpc_server_spec.rb24
-rw-r--r--src/ruby/spec/google_rpc_status_utils_spec.rb5
-rw-r--r--src/ruby/spec/pb/health/checker_spec.rb2
-rw-r--r--src/ruby/spec/server_spec.rb18
-rw-r--r--src/ruby/spec/support/helpers.rb36
11 files changed, 69 insertions, 33 deletions
diff --git a/src/ruby/spec/channel_connection_spec.rb b/src/ruby/spec/channel_connection_spec.rb
index ce3e3b1c93..5c31f41065 100644
--- a/src/ruby/spec/channel_connection_spec.rb
+++ b/src/ruby/spec/channel_connection_spec.rb
@@ -16,9 +16,10 @@ require 'timeout'
include Timeout
include GRPC::Core
+include GRPC::Spec::Helpers
def start_server(port = 0)
- @srv = GRPC::RpcServer.new(pool_size: 1)
+ @srv = new_rpc_server_for_testing(pool_size: 1)
server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure)
@srv.handle(EchoService)
@server_thd = Thread.new { @srv.run }
diff --git a/src/ruby/spec/client_auth_spec.rb b/src/ruby/spec/client_auth_spec.rb
index 79c9192aa5..b955ad231e 100644
--- a/src/ruby/spec/client_auth_spec.rb
+++ b/src/ruby/spec/client_auth_spec.rb
@@ -95,7 +95,7 @@ describe 'client-server auth' do
server_opts = {
poll_period: 1
}
- @srv = RpcServer.new(**server_opts)
+ @srv = new_rpc_server_for_testing(**server_opts)
port = @srv.add_http2_port('0.0.0.0:0', create_server_creds)
@srv.handle(SslTestService)
@srv_thd = Thread.new { @srv.run }
diff --git a/src/ruby/spec/client_server_spec.rb b/src/ruby/spec/client_server_spec.rb
index adab8c9d14..14ad369ac8 100644
--- a/src/ruby/spec/client_server_spec.rb
+++ b/src/ruby/spec/client_server_spec.rb
@@ -542,7 +542,7 @@ end
describe 'the http client/server' do
before(:example) do
server_host = '0.0.0.0:0'
- @server = GRPC::Core::Server.new(nil)
+ @server = new_core_server_for_testing(nil)
server_port = @server.add_http2_port(server_host, :this_port_is_insecure)
@server.start
@ch = Channel.new("0.0.0.0:#{server_port}", nil, :this_channel_is_insecure)
@@ -574,7 +574,7 @@ describe 'the secure http client/server' do
server_host = '0.0.0.0:0'
server_creds = GRPC::Core::ServerCredentials.new(
nil, [{ private_key: certs[1], cert_chain: certs[2] }], false)
- @server = GRPC::Core::Server.new(nil)
+ @server = new_core_server_for_testing(nil)
server_port = @server.add_http2_port(server_host, server_creds)
@server.start
args = { Channel::SSL_TARGET => 'foo.test.google.fr' }
diff --git a/src/ruby/spec/generic/active_call_spec.rb b/src/ruby/spec/generic/active_call_spec.rb
index 120acc35af..135d1f28bf 100644
--- a/src/ruby/spec/generic/active_call_spec.rb
+++ b/src/ruby/spec/generic/active_call_spec.rb
@@ -40,7 +40,7 @@ describe GRPC::ActiveCall do
before(:each) do
@pass_through = proc { |x| x }
host = '0.0.0.0:0'
- @server = GRPC::Core::Server.new(nil)
+ @server = new_core_server_for_testing(nil)
server_port = @server.add_http2_port(host, :this_port_is_insecure)
@server.start
@ch = GRPC::Core::Channel.new("0.0.0.0:#{server_port}", nil,
diff --git a/src/ruby/spec/generic/client_stub_spec.rb b/src/ruby/spec/generic/client_stub_spec.rb
index 9539e56c0f..79eeca9197 100644
--- a/src/ruby/spec/generic/client_stub_spec.rb
+++ b/src/ruby/spec/generic/client_stub_spec.rb
@@ -888,12 +888,12 @@ describe 'ClientStub' do
secure_credentials = GRPC::Core::ServerCredentials.new(
nil, [{ private_key: certs[1], cert_chain: certs[2] }], false)
- @server = GRPC::Core::Server.new(nil)
+ @server = new_core_server_for_testing(nil)
@server.add_http2_port('0.0.0.0:0', secure_credentials)
end
def create_test_server
- @server = GRPC::Core::Server.new(nil)
+ @server = new_core_server_for_testing(nil)
@server.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
end
diff --git a/src/ruby/spec/generic/interceptor_registry_spec.rb b/src/ruby/spec/generic/interceptor_registry_spec.rb
index f93f5cec09..eb75d1e0b2 100644
--- a/src/ruby/spec/generic/interceptor_registry_spec.rb
+++ b/src/ruby/spec/generic/interceptor_registry_spec.rb
@@ -14,7 +14,7 @@
require 'spec_helper'
describe GRPC::InterceptorRegistry do
- let(:server) { RpcServer.new }
+ let(:server) { new_rpc_server_for_testing }
let(:interceptor) { TestServerInterceptor.new }
let(:interceptors) { [interceptor] }
let(:registry) { described_class.new(interceptors) }
diff --git a/src/ruby/spec/generic/rpc_server_spec.rb b/src/ruby/spec/generic/rpc_server_spec.rb
index 05059fbecf..e072d0c45f 100644
--- a/src/ruby/spec/generic/rpc_server_spec.rb
+++ b/src/ruby/spec/generic/rpc_server_spec.rb
@@ -172,7 +172,7 @@ describe GRPC::RpcServer do
it 'can be created with just some args' do
opts = { server_args: { a_channel_arg: 'an_arg' } }
blk = proc do
- RpcServer.new(**opts)
+ new_rpc_server_for_testing(**opts)
end
expect(&blk).not_to raise_error
end
@@ -183,7 +183,7 @@ describe GRPC::RpcServer do
server_args: { a_channel_arg: 'an_arg' },
creds: Object.new
}
- RpcServer.new(**opts)
+ new_rpc_server_for_testing(**opts)
end
expect(&blk).to raise_error
end
@@ -192,7 +192,7 @@ describe GRPC::RpcServer do
describe '#stopped?' do
before(:each) do
opts = { server_args: { a_channel_arg: 'an_arg' }, poll_period: 1.5 }
- @srv = RpcServer.new(**opts)
+ @srv = new_rpc_server_for_testing(**opts)
@srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
end
@@ -224,7 +224,7 @@ describe GRPC::RpcServer do
opts = {
server_args: { a_channel_arg: 'an_arg' }
}
- r = RpcServer.new(**opts)
+ r = new_rpc_server_for_testing(**opts)
expect(r.running?).to be(false)
end
@@ -233,7 +233,7 @@ describe GRPC::RpcServer do
server_args: { a_channel_arg: 'an_arg' },
poll_period: 2
}
- r = RpcServer.new(**opts)
+ r = new_rpc_server_for_testing(**opts)
r.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
expect { r.run }.to raise_error(RuntimeError)
end
@@ -243,7 +243,7 @@ describe GRPC::RpcServer do
server_args: { a_channel_arg: 'an_arg' },
poll_period: 2.5
}
- r = RpcServer.new(**opts)
+ r = new_rpc_server_for_testing(**opts)
r.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
r.handle(EchoService)
t = Thread.new { r.run }
@@ -257,7 +257,7 @@ describe GRPC::RpcServer do
describe '#handle' do
before(:each) do
@opts = { server_args: { a_channel_arg: 'an_arg' }, poll_period: 1 }
- @srv = RpcServer.new(**@opts)
+ @srv = new_rpc_server_for_testing(**@opts)
@srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
end
@@ -303,7 +303,7 @@ describe GRPC::RpcServer do
server_opts = {
poll_period: 1
}
- @srv = RpcServer.new(**server_opts)
+ @srv = new_rpc_server_for_testing(**server_opts)
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)
@@ -474,7 +474,7 @@ describe GRPC::RpcServer do
poll_period: 1,
max_waiting_requests: 1
}
- alt_srv = RpcServer.new(**opts)
+ alt_srv = new_rpc_server_for_testing(**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}"
@@ -538,7 +538,7 @@ describe GRPC::RpcServer do
poll_period: 1,
connect_md_proc: test_md_proc
}
- @srv = RpcServer.new(**server_opts)
+ @srv = new_rpc_server_for_testing(**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
@@ -573,7 +573,7 @@ describe GRPC::RpcServer do
server_opts = {
poll_period: 1
}
- @srv = RpcServer.new(**server_opts)
+ @srv = new_rpc_server_for_testing(**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
@@ -624,7 +624,7 @@ describe GRPC::RpcServer do
server_opts = {
poll_period: 1
}
- @srv = RpcServer.new(**server_opts)
+ @srv = new_rpc_server_for_testing(**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}"
diff --git a/src/ruby/spec/google_rpc_status_utils_spec.rb b/src/ruby/spec/google_rpc_status_utils_spec.rb
index 6f2a06b1d9..3263589b6a 100644
--- a/src/ruby/spec/google_rpc_status_utils_spec.rb
+++ b/src/ruby/spec/google_rpc_status_utils_spec.rb
@@ -19,6 +19,7 @@ require_relative '../pb/src/proto/grpc/testing/messages_pb'
require 'google/protobuf/well_known_types'
include GRPC::Core
+include GRPC::Spec::Helpers
describe 'conversion from a status struct to a google protobuf status' do
it 'fails if the input is not a status struct' do
@@ -150,7 +151,7 @@ GoogleRpcStatusTestStub = GoogleRpcStatusTestService.rpc_stub_class
describe 'receving a google rpc status from a remote endpoint' do
def start_server(encoded_rpc_status)
- @srv = GRPC::RpcServer.new(pool_size: 1)
+ @srv = new_rpc_server_for_testing(pool_size: 1)
@server_port = @srv.add_http2_port('localhost:0',
:this_port_is_insecure)
@srv.handle(GoogleRpcStatusTestService.new(encoded_rpc_status))
@@ -238,7 +239,7 @@ NoStatusDetailsBinTestServiceStub = NoStatusDetailsBinTestService.rpc_stub_class
describe 'when the endpoint doesnt send grpc-status-details-bin' do
def start_server
- @srv = GRPC::RpcServer.new(pool_size: 1)
+ @srv = new_rpc_server_for_testing(pool_size: 1)
@server_port = @srv.add_http2_port('localhost:0',
:this_port_is_insecure)
@srv.handle(NoStatusDetailsBinTestService)
diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb
index c79ccfd2e0..58a602327c 100644
--- a/src/ruby/spec/pb/health/checker_spec.rb
+++ b/src/ruby/spec/pb/health/checker_spec.rb
@@ -192,7 +192,7 @@ describe Grpc::Health::Checker do
server_opts = {
poll_period: 1
}
- @srv = RpcServer.new(**server_opts)
+ @srv = new_rpc_server_for_testing(**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)
diff --git a/src/ruby/spec/server_spec.rb b/src/ruby/spec/server_spec.rb
index c0a59572b1..a0d27b66f5 100644
--- a/src/ruby/spec/server_spec.rb
+++ b/src/ruby/spec/server_spec.rb
@@ -30,12 +30,12 @@ describe Server do
describe '#start' do
it 'runs without failing' do
- blk = proc { Server.new(nil).start }
+ blk = proc { new_core_server_for_testing(nil).start }
expect(&blk).to_not raise_error
end
it 'fails if the server is closed' do
- s = Server.new(nil)
+ s = new_core_server_for_testing(nil)
s.close
expect { s.start }.to raise_error(RuntimeError)
end
@@ -85,7 +85,7 @@ describe Server do
describe 'for insecure servers' do
it 'runs without failing' do
blk = proc do
- s = Server.new(nil)
+ s = new_core_server_for_testing(nil)
s.add_http2_port('localhost:0', :this_port_is_insecure)
s.close
end
@@ -93,7 +93,7 @@ describe Server do
end
it 'fails if the server is closed' do
- s = Server.new(nil)
+ s = new_core_server_for_testing(nil)
s.close
blk = proc do
s.add_http2_port('localhost:0', :this_port_is_insecure)
@@ -106,7 +106,7 @@ describe Server do
let(:cert) { create_test_cert }
it 'runs without failing' do
blk = proc do
- s = Server.new(nil)
+ s = new_core_server_for_testing(nil)
s.add_http2_port('localhost:0', cert)
s.close
end
@@ -114,7 +114,7 @@ describe Server do
end
it 'fails if the server is closed' do
- s = Server.new(nil)
+ s = new_core_server_for_testing(nil)
s.close
blk = proc { s.add_http2_port('localhost:0', cert) }
expect(&blk).to raise_error(RuntimeError)
@@ -124,7 +124,7 @@ describe Server do
shared_examples '#new' do
it 'takes nil channel args' do
- expect { Server.new(nil) }.to_not raise_error
+ expect { new_core_server_for_testing(nil) }.to_not raise_error
end
it 'does not take a hash with bad keys as channel args' do
@@ -175,14 +175,14 @@ describe Server do
describe '#new with an insecure channel' do
def construct_with_args(a)
- proc { Server.new(a) }
+ proc { new_core_server_for_testing(a) }
end
it_behaves_like '#new'
end
def start_a_server
- s = Server.new(nil)
+ s = new_core_server_for_testing(nil)
s.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
s.start
s
diff --git a/src/ruby/spec/support/helpers.rb b/src/ruby/spec/support/helpers.rb
index 65fffff9e7..29028df8b7 100644
--- a/src/ruby/spec/support/helpers.rb
+++ b/src/ruby/spec/support/helpers.rb
@@ -31,7 +31,7 @@ module GRPC
#
def build_rpc_server(server_opts: {},
client_opts: {})
- @server = RpcServer.new({ poll_period: 1 }.merge(server_opts))
+ @server = new_rpc_server_for_testing({ poll_period: 1 }.merge(server_opts))
@port = @server.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
@host = "0.0.0.0:#{@port}"
@client_opts = client_opts
@@ -68,6 +68,40 @@ module GRPC
opts ||= @client_opts
klass.new(host, :this_channel_is_insecure, **opts)
end
+
+ ##
+ # Build an RPCServer for use in tests. Adds args
+ # that are useful for all tests.
+ #
+ # @param [Hash] server_opts
+ #
+ def new_rpc_server_for_testing(server_opts = {})
+ server_opts[:server_args] ||= {}
+ update_server_args_hash(server_opts[:server_args])
+ RpcServer.new(**server_opts)
+ end
+
+ ##
+ # Build an GRPC::Core::Server for use in tests. Adds args
+ # that are useful for all tests.
+ #
+ # @param [Hash] server_args
+ #
+ def new_core_server_for_testing(server_args)
+ server_args.nil? && server_args = {}
+ update_server_args_hash(server_args)
+ GRPC::Core::Server.new(server_args)
+ end
+
+ def update_server_args_hash(server_args)
+ so_reuseport_arg = 'grpc.so_reuseport'
+ unless server_args[so_reuseport_arg].nil?
+ fail 'Unexpected. grpc.so_reuseport already set.'
+ end
+ # Run tests without so_reuseport to eliminate the chance of
+ # cross-talk.
+ server_args[so_reuseport_arg] = 0
+ end
end
end
end