add end2end tests to formatter and adjust to formatter

pull/9986/head
Alexander Polcyn 8 years ago
parent b862b6ae20
commit 4e606751db
  1. 3
      Rakefile
  2. 1
      src/ruby/.rubocop.yml
  3. 6
      src/ruby/end2end/channel_closing_client.rb
  4. 16
      src/ruby/end2end/channel_closing_driver.rb
  5. 7
      src/ruby/end2end/channel_state_client.rb
  6. 11
      src/ruby/end2end/channel_state_driver.rb
  7. 22
      src/ruby/end2end/end2end_common.rb
  8. 25
      src/ruby/end2end/sig_handling_client.rb
  9. 9
      src/ruby/end2end/sig_handling_driver.rb

@ -12,7 +12,8 @@ load 'tools/distrib/docker_for_windows.rb'
# Add rubocop style checking tasks # Add rubocop style checking tasks
RuboCop::RakeTask.new(:rubocop) do |task| RuboCop::RakeTask.new(:rubocop) do |task|
task.options = ['-c', 'src/ruby/.rubocop.yml'] task.options = ['-c', 'src/ruby/.rubocop.yml']
task.patterns = ['src/ruby/{lib,spec}/**/*.rb'] # add end2end tests to formatter but don't add generated proto _pb.rb's
task.patterns = ['src/ruby/{lib,spec}/**/*.rb', 'src/ruby/end2end/*.rb']
end end
spec = Gem::Specification.load('grpc.gemspec') spec = Gem::Specification.load('grpc.gemspec')

@ -9,6 +9,7 @@ AllCops:
- 'bin/math_services_pb.rb' - 'bin/math_services_pb.rb'
- 'pb/grpc/health/v1/*' - 'pb/grpc/health/v1/*'
- 'pb/test/**/*' - 'pb/test/**/*'
- 'end2end/lib/*'
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 9 Max: 9

@ -31,10 +31,13 @@
require_relative './end2end_common' require_relative './end2end_common'
# Calls '#close' on a Channel when "shutdown" called. This tries to
# trigger a hang or crash bug by closing a channel actively being watched
class ChannelClosingClientController < ClientControl::ClientController::Service class ChannelClosingClientController < ClientControl::ClientController::Service
def initialize(ch) def initialize(ch)
@ch = ch @ch = ch
end end
def shutdown(_, _) def shutdown(_, _)
@ch.close @ch.close
ClientControl::Void.new ClientControl::Void.new
@ -53,7 +56,8 @@ def main
end end
end.parse! end.parse!
ch = GRPC::Core::Channel.new("localhost:#{server_port}", {}, :this_channel_is_insecure) ch = GRPC::Core::Channel.new("localhost:#{server_port}", {},
:this_channel_is_insecure)
srv = GRPC::RpcServer.new srv = GRPC::RpcServer.new
thd = Thread.new do thd = Thread.new do

@ -29,23 +29,24 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# make sure that the client doesn't hang when channel is closed explictly while it's used # make sure that the client doesn't hang when channel is closed
# explictly while it's used
require_relative './end2end_common' require_relative './end2end_common'
def main def main
STDERR.puts "start server" STDERR.puts 'start server'
server_runner = ServerRunner.new server_runner = ServerRunner.new
server_port = server_runner.run server_port = server_runner.run
sleep 1 sleep 1
STDERR.puts "start client" STDERR.puts 'start client'
control_stub, client_pid = start_client("channel_closing_client.rb", server_port) control_stub, client_pid = start_client('channel_closing_client.rb',
server_port)
sleep 3 sleep 3
begin begin
Timeout.timeout(10) do Timeout.timeout(10) do
control_stub.shutdown(ClientControl::Void.new) control_stub.shutdown(ClientControl::Void.new)
@ -55,8 +56,9 @@ def main
STDERR.puts "timeout wait for client pid #{client_pid}" STDERR.puts "timeout wait for client pid #{client_pid}"
Process.kill('SIGKILL', client_pid) Process.kill('SIGKILL', client_pid)
Process.wait(client_pid) Process.wait(client_pid)
STDERR.puts "killed client child" STDERR.puts 'killed client child'
raise 'Timed out waiting for client process. It likely hangs when a channel is closed while connectivity is watched' raise 'Timed out waiting for client process. It likely hangs when a ' \
'channel is closed while connectivity is watched'
end end
server_runner.stop server_runner.stop

@ -34,15 +34,16 @@ require_relative './end2end_common'
def main def main
server_port = '' server_port = ''
OptionParser.new do |opts| OptionParser.new do |opts|
opts.on('--client_control_port=P', String) do |p| opts.on('--client_control_port=P', String) do
STDERR.puts "client_control_port ignored" STDERR.puts 'client_control_port ignored'
end end
opts.on('--server_port=P', String) do |p| opts.on('--server_port=P', String) do |p|
server_port = p server_port = p
end end
end.parse! end.parse!
ch = GRPC::Core::Channel.new("localhost:#{server_port}", {}, :this_channel_is_insecure) ch = GRPC::Core::Channel.new("localhost:#{server_port}", {},
:this_channel_is_insecure)
loop do loop do
state = ch.connectivity_state state = ch.connectivity_state

@ -34,14 +34,14 @@
require_relative './end2end_common' require_relative './end2end_common'
def main def main
STDERR.puts "start server" STDERR.puts 'start server'
server_runner = ServerRunner.new server_runner = ServerRunner.new
server_port = server_runner.run server_port = server_runner.run
sleep 1 sleep 1
STDERR.puts "start client" STDERR.puts 'start client'
_, client_pid = start_client("channel_state_client.rb", server_port) _, client_pid = start_client('channel_state_client.rb', server_port)
sleep 3 sleep 3
@ -53,8 +53,9 @@ def main
STDERR.puts "timeout wait for client pid #{client_pid}" STDERR.puts "timeout wait for client pid #{client_pid}"
Process.kill('SIGKILL', client_pid) Process.kill('SIGKILL', client_pid)
Process.wait(client_pid) Process.wait(client_pid)
STDERR.puts "killed client child" STDERR.puts 'killed client child'
raise 'Timed out waiting for client process. It likely hangs when ended abruptly' raise 'Timed out waiting for client process. ' \
'It likely hangs when ended abruptly'
end end
server_runner.stop server_runner.stop

@ -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

@ -31,20 +31,25 @@
require_relative './end2end_common' require_relative './end2end_common'
# Test client. Sends RPC's as normal but process also has signal handlers
class SigHandlingClientController < ClientControl::ClientController::Service class SigHandlingClientController < ClientControl::ClientController::Service
def initialize(srv, stub) def initialize(srv, stub)
@srv = srv @srv = srv
@stub = stub @stub = stub
end end
def do_echo_rpc(req, _) def do_echo_rpc(req, _)
response = @stub.echo(Echo::EchoRequest.new(request: req.request)) response = @stub.echo(Echo::EchoRequest.new(request: req.request))
raise "bad response" unless response.response == req.request fail 'bad response' unless response.response == req.request
ClientControl::Void.new ClientControl::Void.new
end end
def shutdown(_, _) def shutdown(_, _)
Thread.new do Thread.new do
#TODO(apolcyn) There is a race between stopping the server and the "shutdown" rpc completing, # TODO(apolcyn) There is a race between stopping the
# See if stop method on server can end active RPC cleanly, to avoid this sleep. # server and the "shutdown" rpc completing,
# See if stop method on server can end active RPC cleanly, to
# avoid this sleep.
sleep 3 sleep 3
@srv.stop @srv.stop
end end
@ -64,17 +69,19 @@ def main
end end
end.parse! end.parse!
Signal.trap("TERM") do Signal.trap('TERM') do
STDERR.puts "SIGTERM received" STDERR.puts 'SIGTERM received'
end end
Signal.trap("INT") do Signal.trap('INT') do
STDERR.puts "SIGINT received" STDERR.puts 'SIGINT received'
end end
srv = GRPC::RpcServer.new srv = GRPC::RpcServer.new
srv.add_http2_port("0.0.0.0:#{client_control_port}", :this_port_is_insecure) srv.add_http2_port("0.0.0.0:#{client_control_port}",
stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", :this_channel_is_insecure) :this_port_is_insecure)
stub = Echo::EchoServer::Stub.new("localhost:#{server_port}",
:this_channel_is_insecure)
srv.handle(SigHandlingClientController.new(srv, stub)) srv.handle(SigHandlingClientController.new(srv, stub))
srv.run srv.run
end end

@ -35,20 +35,21 @@
require_relative './end2end_common' require_relative './end2end_common'
def main def main
STDERR.puts "start server" STDERR.puts 'start server'
server_runner = ServerRunner.new server_runner = ServerRunner.new
server_port = server_runner.run server_port = server_runner.run
sleep 1 sleep 1
STDERR.puts "start client" STDERR.puts 'start client'
control_stub, client_pid = start_client("sig_handling_client.rb", server_port) control_stub, client_pid = start_client('sig_handling_client.rb', server_port)
sleep 1 sleep 1
count = 0 count = 0
while count < 5 while count < 5
control_stub.do_echo_rpc(ClientControl::DoEchoRpcRequest.new(request: 'hello')) control_stub.do_echo_rpc(
ClientControl::DoEchoRpcRequest.new(request: 'hello'))
Process.kill('SIGTERM', client_pid) Process.kill('SIGTERM', client_pid)
Process.kill('SIGINT', client_pid) Process.kill('SIGINT', client_pid)
count += 1 count += 1

Loading…
Cancel
Save