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. 18
      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
RuboCop::RakeTask.new(:rubocop) do |task|
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
spec = Gem::Specification.load('grpc.gemspec')

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

@ -31,10 +31,13 @@
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
def initialize(ch)
@ch = ch
end
def shutdown(_, _)
@ch.close
ClientControl::Void.new
@ -53,7 +56,8 @@ def main
end
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
thd = Thread.new do

@ -29,23 +29,24 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# 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'
def main
STDERR.puts "start server"
STDERR.puts 'start server'
server_runner = ServerRunner.new
server_port = server_runner.run
sleep 1
STDERR.puts "start client"
control_stub, client_pid = start_client("channel_closing_client.rb", server_port)
STDERR.puts 'start client'
control_stub, client_pid = start_client('channel_closing_client.rb',
server_port)
sleep 3
begin
Timeout.timeout(10) do
control_stub.shutdown(ClientControl::Void.new)
@ -55,8 +56,9 @@ def main
STDERR.puts "timeout wait for client pid #{client_pid}"
Process.kill('SIGKILL', client_pid)
Process.wait(client_pid)
STDERR.puts "killed client child"
raise 'Timed out waiting for client process. It likely hangs when a channel is closed while connectivity is watched'
STDERR.puts 'killed client child'
raise 'Timed out waiting for client process. It likely hangs when a ' \
'channel is closed while connectivity is watched'
end
server_runner.stop

@ -34,15 +34,16 @@ require_relative './end2end_common'
def main
server_port = ''
OptionParser.new do |opts|
opts.on('--client_control_port=P', String) do |p|
STDERR.puts "client_control_port ignored"
opts.on('--client_control_port=P', String) do
STDERR.puts 'client_control_port ignored'
end
opts.on('--server_port=P', String) do |p|
server_port = p
end
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
state = ch.connectivity_state

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

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

@ -31,20 +31,25 @@
require_relative './end2end_common'
# Test client. Sends RPC's as normal but process also has signal handlers
class SigHandlingClientController < ClientControl::ClientController::Service
def initialize(srv, stub)
@srv = srv
@stub = stub
end
def do_echo_rpc(req, _)
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
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.
# 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
@ -64,17 +69,19 @@ def main
end
end.parse!
Signal.trap("TERM") do
STDERR.puts "SIGTERM received"
Signal.trap('TERM') do
STDERR.puts 'SIGTERM received'
end
Signal.trap("INT") do
STDERR.puts "SIGINT received"
Signal.trap('INT') do
STDERR.puts 'SIGINT received'
end
srv = GRPC::RpcServer.new
srv.add_http2_port("0.0.0.0:#{client_control_port}", :this_port_is_insecure)
stub = Echo::EchoServer::Stub.new("localhost:#{server_port}", :this_channel_is_insecure)
srv.add_http2_port("0.0.0.0:#{client_control_port}",
:this_port_is_insecure)
stub = Echo::EchoServer::Stub.new("localhost:#{server_port}",
:this_channel_is_insecure)
srv.handle(SigHandlingClientController.new(srv, stub))
srv.run
end

@ -35,20 +35,21 @@
require_relative './end2end_common'
def main
STDERR.puts "start server"
STDERR.puts 'start server'
server_runner = ServerRunner.new
server_port = server_runner.run
sleep 1
STDERR.puts "start client"
control_stub, client_pid = start_client("sig_handling_client.rb", server_port)
STDERR.puts 'start client'
control_stub, client_pid = start_client('sig_handling_client.rb', server_port)
sleep 1
count = 0
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('SIGINT', client_pid)
count += 1

Loading…
Cancel
Save