aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/end2end
diff options
context:
space:
mode:
authorGravatar Alexander Polcyn <apolcyn@google.com>2017-03-14 17:44:21 -0700
committerGravatar Alexander Polcyn <apolcyn@google.com>2017-03-14 23:30:39 -0700
commitc44c16e330a8532c8c917c2aa64ffd1aeafe0126 (patch)
tree1f3b5da7bdacecb4515071c197ae316fdd3fdb13 /src/ruby/end2end
parentbe30114a3b95b6dc843f8338d2b8a5470bec2553 (diff)
add initial framework for full end2end tests outside of rspec
Diffstat (limited to 'src/ruby/end2end')
-rwxr-xr-xsrc/ruby/end2end/echo_server.rb68
-rw-r--r--src/ruby/end2end/gen_protos.sh2
-rw-r--r--src/ruby/end2end/lib/client_control_pb.rb21
-rw-r--r--src/ruby/end2end/lib/client_control_services_pb.rb54
-rw-r--r--src/ruby/end2end/lib/echo_pb.rb18
-rw-r--r--src/ruby/end2end/lib/echo_services_pb.rb52
-rw-r--r--src/ruby/end2end/protos/client_control.proto48
-rw-r--r--src/ruby/end2end/protos/echo.proto46
-rwxr-xr-xsrc/ruby/end2end/sig_handling_client.rb91
-rwxr-xr-xsrc/ruby/end2end/sig_handling_driver.rb88
10 files changed, 488 insertions, 0 deletions
diff --git a/src/ruby/end2end/echo_server.rb b/src/ruby/end2end/echo_server.rb
new file mode 100755
index 0000000000..5e80740aa0
--- /dev/null
+++ b/src/ruby/end2end/echo_server.rb
@@ -0,0 +1,68 @@
+#!/usr/bin/env ruby
+
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+this_dir = File.expand_path(File.dirname(__FILE__))
+protos_lib_dir = File.join(this_dir, 'lib')
+grpc_lib_dir = File.join(File.dirname(this_dir), 'lib')
+$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir)
+$LOAD_PATH.unshift(protos_lib_dir) unless $LOAD_PATH.include?(protos_lib_dir)
+$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
+
+require 'grpc'
+require 'echo_services_pb'
+
+# GreeterServer is simple server that implements the Helloworld Greeter server.
+class EchoServerImpl < Echo::EchoServer::Service
+ # say_hello implements the SayHello rpc method.
+ def echo(echo_req, _)
+ Echo::EchoReply.new(response: echo_req.request)
+ end
+end
+
+class ServerRunner
+ def initialize(port)
+ @port = port
+ end
+ def run
+ @srv = GRPC::RpcServer.new
+ @thd = Thread.new do
+ @srv.add_http2_port("localhost:#{@port}", :this_port_is_insecure)
+ @srv.handle(EchoServerImpl)
+ @srv.run
+ end
+ @srv.wait_till_running
+ end
+ def stop
+ @srv.stop
+ @thd.join
+ raise "server not stopped" unless @srv.stopped?
+ end
+end
diff --git a/src/ruby/end2end/gen_protos.sh b/src/ruby/end2end/gen_protos.sh
new file mode 100644
index 0000000000..c26b5572da
--- /dev/null
+++ b/src/ruby/end2end/gen_protos.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+grpc_tools_ruby_protoc -I protos --ruby_out=lib --grpc_out=lib protos/echo.proto protos/client_control.proto
diff --git a/src/ruby/end2end/lib/client_control_pb.rb b/src/ruby/end2end/lib/client_control_pb.rb
new file mode 100644
index 0000000000..866095a80a
--- /dev/null
+++ b/src/ruby/end2end/lib/client_control_pb.rb
@@ -0,0 +1,21 @@
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: client_control.proto
+
+require 'google/protobuf'
+
+Google::Protobuf::DescriptorPool.generated_pool.build do
+ add_message "client_control.DoEchoRpcRequest" do
+ optional :request, :string, 1
+ end
+ add_message "client_control.CreateClientStubRequest" do
+ optional :server_address, :string, 1
+ end
+ add_message "client_control.Void" do
+ end
+end
+
+module ClientControl
+ DoEchoRpcRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("client_control.DoEchoRpcRequest").msgclass
+ CreateClientStubRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("client_control.CreateClientStubRequest").msgclass
+ Void = Google::Protobuf::DescriptorPool.generated_pool.lookup("client_control.Void").msgclass
+end
diff --git a/src/ruby/end2end/lib/client_control_services_pb.rb b/src/ruby/end2end/lib/client_control_services_pb.rb
new file mode 100644
index 0000000000..4c31f3e590
--- /dev/null
+++ b/src/ruby/end2end/lib/client_control_services_pb.rb
@@ -0,0 +1,54 @@
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# Source: client_control.proto for package 'client_control'
+# Original file comments:
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+require 'grpc'
+require 'client_control_pb'
+
+module ClientControl
+ module ClientController
+ class Service
+
+ include GRPC::GenericService
+
+ self.marshal_class_method = :encode
+ self.unmarshal_class_method = :decode
+ self.service_name = 'client_control.ClientController'
+
+ rpc :DoEchoRpc, DoEchoRpcRequest, Void
+ rpc :CreateClientStub, CreateClientStubRequest, Void
+ rpc :Shutdown, Void, Void
+ end
+
+ Stub = Service.rpc_stub_class
+ end
+end
diff --git a/src/ruby/end2end/lib/echo_pb.rb b/src/ruby/end2end/lib/echo_pb.rb
new file mode 100644
index 0000000000..c62adc0753
--- /dev/null
+++ b/src/ruby/end2end/lib/echo_pb.rb
@@ -0,0 +1,18 @@
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: echo.proto
+
+require 'google/protobuf'
+
+Google::Protobuf::DescriptorPool.generated_pool.build do
+ add_message "echo.EchoRequest" do
+ optional :request, :string, 1
+ end
+ add_message "echo.EchoReply" do
+ optional :response, :string, 1
+ end
+end
+
+module Echo
+ EchoRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("echo.EchoRequest").msgclass
+ EchoReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("echo.EchoReply").msgclass
+end
diff --git a/src/ruby/end2end/lib/echo_services_pb.rb b/src/ruby/end2end/lib/echo_services_pb.rb
new file mode 100644
index 0000000000..c66e975bf3
--- /dev/null
+++ b/src/ruby/end2end/lib/echo_services_pb.rb
@@ -0,0 +1,52 @@
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# Source: echo.proto for package 'echo'
+# Original file comments:
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+require 'grpc'
+require 'echo_pb'
+
+module Echo
+ module EchoServer
+ class Service
+
+ include GRPC::GenericService
+
+ self.marshal_class_method = :encode
+ self.unmarshal_class_method = :decode
+ self.service_name = 'echo.EchoServer'
+
+ rpc :Echo, EchoRequest, EchoReply
+ end
+
+ Stub = Service.rpc_stub_class
+ end
+end
diff --git a/src/ruby/end2end/protos/client_control.proto b/src/ruby/end2end/protos/client_control.proto
new file mode 100644
index 0000000000..5e11876cb4
--- /dev/null
+++ b/src/ruby/end2end/protos/client_control.proto
@@ -0,0 +1,48 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto3";
+
+package client_control;
+
+service ClientController {
+ rpc DoEchoRpc (DoEchoRpcRequest) returns (Void) {}
+ rpc CreateClientStub(CreateClientStubRequest) returns (Void) {}
+ rpc Shutdown(Void) returns (Void) {}
+}
+
+message DoEchoRpcRequest {
+ string request = 1;
+}
+
+message CreateClientStubRequest {
+ string server_address = 1;
+}
+
+message Void{}
diff --git a/src/ruby/end2end/protos/echo.proto b/src/ruby/end2end/protos/echo.proto
new file mode 100644
index 0000000000..d47afef70f
--- /dev/null
+++ b/src/ruby/end2end/protos/echo.proto
@@ -0,0 +1,46 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+syntax = "proto3";
+
+package echo;
+
+service EchoServer {
+ rpc Echo (EchoRequest) returns (EchoReply) {}
+}
+
+// The request message containing the user's name.
+message EchoRequest {
+ string request = 1;
+}
+
+// The response message containing the greetings
+message EchoReply {
+ string response = 1;
+}
diff --git a/src/ruby/end2end/sig_handling_client.rb b/src/ruby/end2end/sig_handling_client.rb
new file mode 100755
index 0000000000..860c6b5f0d
--- /dev/null
+++ b/src/ruby/end2end/sig_handling_client.rb
@@ -0,0 +1,91 @@
+#!/usr/bin/env ruby
+
+# Copyright 2015, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+this_dir = File.expand_path(File.dirname(__FILE__))
+protos_lib_dir = File.join(this_dir, 'lib')
+grpc_lib_dir = File.join(File.dirname(this_dir), 'lib')
+$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir)
+$LOAD_PATH.unshift(protos_lib_dir) unless $LOAD_PATH.include?(protos_lib_dir)
+$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
+
+require 'grpc'
+require 'echo_services_pb'
+require 'client_control_services_pb'
+require 'optparse'
+require 'thread'
+
+class SigHandlingClientController < ClientControl::ClientController::Service
+ def initialize(srv)
+ @srv = srv
+ end
+ def do_echo_rpc(req, _)
+ response = @stub.echo(Echo::EchoRequest.new(request: req.request))
+ raise "bad response" unless response.response == req.request
+ ClientControl::Void.new
+ end
+ def create_client_stub(req, _)
+ @stub = Echo::EchoServer::Stub.new(req.server_address, :this_channel_is_insecure)
+ ClientControl::Void.new
+ end
+ def shutdown(_, _)
+ Thread.new do
+ #TODO(apolcyn) There is a race between stopping the server and the "shutdown" rpc completing,
+ # See if stop method on server can end active RPC cleanly, to avoid this sleep.
+ sleep 3
+ @srv.stop
+ end
+ ClientControl::Void.new
+ end
+end
+
+def main
+ client_control_port = ''
+ OptionParser.new do |opts|
+ opts.on('--client_control_port=P', String) do |p|
+ client_control_port = p
+ end
+ end.parse!
+
+ Signal.trap("TERM") do
+ STDERR.puts "SIGTERM received"
+ end
+
+ Signal.trap("INT") do
+ STDERR.puts "SIGINT received"
+ end
+
+ srv = GRPC::RpcServer.new
+ srv.add_http2_port("localhost:#{client_control_port}", :this_port_is_insecure)
+ srv.handle(SigHandlingClientController.new(srv))
+ srv.run
+end
+
+main
diff --git a/src/ruby/end2end/sig_handling_driver.rb b/src/ruby/end2end/sig_handling_driver.rb
new file mode 100755
index 0000000000..524f0cebe8
--- /dev/null
+++ b/src/ruby/end2end/sig_handling_driver.rb
@@ -0,0 +1,88 @@
+#!/usr/bin/env ruby
+
+# Copyright 2016, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# smoke test for a grpc-using app that receives and
+# handles process-ending signals
+
+this_dir = File.expand_path(File.dirname(__FILE__))
+protos_lib_dir = File.join(this_dir, 'lib')
+grpc_lib_dir = File.join(File.dirname(this_dir), 'lib')
+$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir)
+$LOAD_PATH.unshift(protos_lib_dir) unless $LOAD_PATH.include?(protos_lib_dir)
+$LOAD_PATH.unshift(this_dir) unless $LOAD_PATH.include?(this_dir)
+
+require 'grpc'
+require 'echo_server'
+require 'client_control_services_pb'
+
+def main
+ this_dir = File.expand_path(File.dirname(__FILE__))
+ lib_dir = File.join(File.dirname(this_dir), 'lib')
+
+ server_port = '50051'
+ STDERR.puts "start server"
+ server_runner = ServerRunner.new(server_port)
+ server_runner.run
+
+ sleep 1
+
+ client_control_port = '50052'
+
+ STDERR.puts "start client"
+ client_path = File.join(this_dir, "sig_handling_client.rb")
+ client_pid = Process.spawn(RbConfig.ruby, client_path, "--client_control_port=#{client_control_port}")
+ control_stub = ClientControl::ClientController::Stub.new("localhost:#{client_control_port}", :this_channel_is_insecure)
+
+ sleep 1
+
+ control_stub.create_client_stub(ClientControl::CreateClientStubRequest.new(server_address: "localhost:#{server_port}"))
+
+ count = 0
+ while count < 5
+ control_stub.do_echo_rpc(ClientControl::DoEchoRpcRequest.new(request: 'hello'))
+ Process.kill('SIGTERM', client_pid)
+ Process.kill('SIGINT', client_pid)
+ count += 1
+ end
+
+ control_stub.shutdown(ClientControl::Void.new)
+ Process.wait(client_pid)
+
+ client_exit_code = $?.exitstatus
+
+ if client_exit_code != 0
+ raise "term sig test failure: client exit code: #{client_exit_code}"
+ end
+
+ server_runner.stop
+end
+
+main