diff options
Diffstat (limited to 'src/ruby/spec/support/helpers.rb')
-rw-r--r-- | src/ruby/spec/support/helpers.rb | 36 |
1 files changed, 35 insertions, 1 deletions
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 |