Debian Codegraph @

src/ruby/end2end/grpc_class_init_test.rb

raw
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
17 require_relative './end2end_common'
18
19 def main
20 native_grpc_classes = %w( channel
21 server
22 channel_credentials
23 xds_channel_credentials
24 server_credentials
25 xds_server_credentials
26 call_credentials
27 compression_options )
28
29 # there is room for false positives in this test,
30 # do a few runs for each config
31 4.times do
32 native_grpc_classes.each do |grpc_class|
33 ['', 'gc', 'concurrency'].each do |stress_test_type|
34 STDERR.puts 'start client'
35 this_dir = File.expand_path(File.dirname(__FILE__))
36 client_path = File.join(this_dir, 'grpc_class_init_client.rb')
37 client_pid = Process.spawn(RbConfig.ruby,
38 client_path,
39 "--grpc_class=#{grpc_class}",
40 "--stress_test=#{stress_test_type}")
41 begin
42 Timeout.timeout(120) do
43 Process.wait(client_pid)
44 end
45 rescue Timeout::Error
46 STDERR.puts "timeout waiting for client pid #{client_pid}"
47 Process.kill('SIGKILL', client_pid)
48 Process.wait(client_pid)
49 STDERR.puts 'killed client child'
50 raise 'Timed out waiting for client process. ' \
51 'It likely freezes when the first constructed gRPC object has ' \
52 "type: #{grpc_class}"
53 end
54
55 client_exit_code = $CHILD_STATUS
56 # concurrency stress test type is expected to exit with a
57 # non-zero status due to an exception being raised
58 if client_exit_code != 0 && stress_test_type != 'concurrency'
59 fail "client failed, exit code #{client_exit_code}"
60 end
61 end
62 end
63 end
64 end
65
66 main