|
|
@ -43,6 +43,7 @@ require 'socket' |
|
|
|
require 'optparse' |
|
|
|
require 'optparse' |
|
|
|
require 'thread' |
|
|
|
require 'thread' |
|
|
|
require 'timeout' |
|
|
|
require 'timeout' |
|
|
|
|
|
|
|
require 'English' # see https://github.com/bbatsov/rubocop/issues/1747 |
|
|
|
|
|
|
|
|
|
|
|
# GreeterServer is simple server that implements the Helloworld Greeter server. |
|
|
|
# GreeterServer is simple server that implements the Helloworld Greeter server. |
|
|
|
class EchoServerImpl < Echo::EchoServer::Service |
|
|
|
class EchoServerImpl < Echo::EchoServer::Service |
|
|
@ -52,9 +53,11 @@ class EchoServerImpl < Echo::EchoServer::Service |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ServerRunner starts an "echo server" that test clients can make calls to |
|
|
|
class ServerRunner |
|
|
|
class ServerRunner |
|
|
|
def initialize |
|
|
|
def initialize |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def run |
|
|
|
def run |
|
|
|
@srv = GRPC::RpcServer.new |
|
|
|
@srv = GRPC::RpcServer.new |
|
|
|
port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) |
|
|
|
port = @srv.add_http2_port('0.0.0.0:0', :this_port_is_insecure) |
|
|
@ -66,10 +69,11 @@ class ServerRunner |
|
|
|
@srv.wait_till_running |
|
|
|
@srv.wait_till_running |
|
|
|
port |
|
|
|
port |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def stop |
|
|
|
def stop |
|
|
|
@srv.stop |
|
|
|
@srv.stop |
|
|
|
@thd.join |
|
|
|
@thd.join |
|
|
|
raise "server not stopped" unless @srv.stopped? |
|
|
|
fail 'server not stopped' unless @srv.stopped? |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -81,22 +85,24 @@ def start_client(client_main, server_port) |
|
|
|
tmp_server.close |
|
|
|
tmp_server.close |
|
|
|
|
|
|
|
|
|
|
|
client_path = File.join(this_dir, client_main) |
|
|
|
client_path = File.join(this_dir, client_main) |
|
|
|
client_pid = Process.spawn(RbConfig.ruby, client_path, |
|
|
|
client_pid = Process.spawn(RbConfig.ruby, |
|
|
|
"--client_control_port=#{client_control_port}", |
|
|
|
client_path, |
|
|
|
"--server_port=#{server_port}") |
|
|
|
"--client_control_port=#{client_control_port}", |
|
|
|
|
|
|
|
"--server_port=#{server_port}") |
|
|
|
sleep 1 |
|
|
|
sleep 1 |
|
|
|
control_stub = ClientControl::ClientController::Stub.new("localhost:#{client_control_port}", :this_channel_is_insecure) |
|
|
|
control_stub = ClientControl::ClientController::Stub.new( |
|
|
|
return control_stub, client_pid |
|
|
|
"localhost:#{client_control_port}", :this_channel_is_insecure) |
|
|
|
|
|
|
|
[control_stub, client_pid] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def cleanup(control_stub, client_pid, server_runner) |
|
|
|
def cleanup(control_stub, client_pid, server_runner) |
|
|
|
control_stub.shutdown(ClientControl::Void.new) |
|
|
|
control_stub.shutdown(ClientControl::Void.new) |
|
|
|
Process.wait(client_pid) |
|
|
|
Process.wait(client_pid) |
|
|
|
|
|
|
|
|
|
|
|
client_exit_code = $?.exitstatus |
|
|
|
client_exit_code = $CHILD_STATUS |
|
|
|
|
|
|
|
|
|
|
|
if client_exit_code != 0 |
|
|
|
if client_exit_code != 0 |
|
|
|
raise "term sig test failure: client exit code: #{client_exit_code}" |
|
|
|
fail "term sig test failure: client exit code: #{client_exit_code}" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
server_runner.stop |
|
|
|
server_runner.stop |
|
|
|