|
|
|
@ -19,51 +19,23 @@ |
|
|
|
|
|
|
|
|
|
require_relative './end2end_common' |
|
|
|
|
|
|
|
|
|
# A service that calls back it's received_rpc_callback |
|
|
|
|
# upon receiving an RPC. Used for synchronization/waiting |
|
|
|
|
# for child process to start. |
|
|
|
|
class ClientStartedService < Echo::EchoServer::Service |
|
|
|
|
def initialize(received_rpc_callback) |
|
|
|
|
@received_rpc_callback = received_rpc_callback |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def echo(echo_req, _) |
|
|
|
|
@received_rpc_callback.call unless @received_rpc_callback.nil? |
|
|
|
|
@received_rpc_callback = nil |
|
|
|
|
Echo::EchoReply.new(response: echo_req.request) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def main |
|
|
|
|
STDERR.puts 'start server' |
|
|
|
|
client_started = false |
|
|
|
|
client_started_mu = Mutex.new |
|
|
|
|
client_started_cv = ConditionVariable.new |
|
|
|
|
received_rpc_callback = proc do |
|
|
|
|
client_started_mu.synchronize do |
|
|
|
|
client_started = true |
|
|
|
|
client_started_cv.signal |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
client_started_service = ClientStartedService.new(received_rpc_callback) |
|
|
|
|
server_runner = ServerRunner.new(client_started_service) |
|
|
|
|
echo_service = EchoServerImpl.new |
|
|
|
|
server_runner = ServerRunner.new(echo_service) |
|
|
|
|
server_port = server_runner.run |
|
|
|
|
STDERR.puts 'start client' |
|
|
|
|
control_stub, client_pid = start_client('graceful_sig_handling_client.rb', server_port) |
|
|
|
|
|
|
|
|
|
client_started_mu.synchronize do |
|
|
|
|
client_started_cv.wait(client_started_mu) until client_started |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# use receipt of one RPC to indicate that the child process is |
|
|
|
|
# ready |
|
|
|
|
echo_service.wait_for_first_rpc_received(20) |
|
|
|
|
# now get the client to send an RPC |
|
|
|
|
control_stub.do_echo_rpc( |
|
|
|
|
ClientControl::DoEchoRpcRequest.new(request: 'hello')) |
|
|
|
|
|
|
|
|
|
STDERR.puts 'killing client' |
|
|
|
|
Process.kill('SIGINT', client_pid) |
|
|
|
|
Process.wait(client_pid) |
|
|
|
|
client_exit_status = $CHILD_STATUS |
|
|
|
|
|
|
|
|
|
if client_exit_status.exited? |
|
|
|
|
if client_exit_status.exitstatus != 0 |
|
|
|
|
STDERR.puts 'Client did not close gracefully' |
|
|
|
@ -75,7 +47,6 @@ def main |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
STDERR.puts 'Client ended gracefully' |
|
|
|
|
|
|
|
|
|
# no need to call cleanup, client should already be dead |
|
|
|
|
server_runner.stop |
|
|
|
|
end |
|
|
|
|