1#!/usr/bin/env ruby 2 3# Copyright 2016 gRPC authors. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17require_relative './end2end_common' 18 19def main 20 native_grpc_classes = %w( channel 21 server 22 channel_credentials 23 call_credentials 24 compression_options ) 25 26 # there is room for false positives in this test, 27 # do a few runs for each config 28 4.times do 29 native_grpc_classes.each do |grpc_class| 30 ['', 'gc', 'concurrency'].each do |stress_test_type| 31 STDERR.puts 'start client' 32 this_dir = File.expand_path(File.dirname(__FILE__)) 33 client_path = File.join(this_dir, 'grpc_class_init_client.rb') 34 client_pid = Process.spawn(RbConfig.ruby, 35 client_path, 36 "--grpc_class=#{grpc_class}", 37 "--stress_test=#{stress_test_type}") 38 begin 39 Timeout.timeout(10) do 40 Process.wait(client_pid) 41 end 42 rescue Timeout::Error 43 STDERR.puts "timeout waiting for client pid #{client_pid}" 44 Process.kill('SIGKILL', client_pid) 45 Process.wait(client_pid) 46 STDERR.puts 'killed client child' 47 raise 'Timed out waiting for client process. ' \ 48 'It likely hangs when the first constructed gRPC object has ' \ 49 "type: #{grpc_class}" 50 end 51 52 client_exit_code = $CHILD_STATUS 53 # concurrency stress test type is expected to exit with a 54 # non-zero status due to an exception being raised 55 if client_exit_code != 0 && stress_test_type != 'concurrency' 56 fail "client failed, exit code #{client_exit_code}" 57 end 58 end 59 end 60 end 61end 62 63main 64