Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | # Copyright 2016 gRPC authors. |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 4 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 8 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 10 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 16 | |
| 17 | # abruptly end a process that has active calls to |
| 18 | # Channel.watch_connectivity_state |
| 19 | |
| 20 | require_relative './end2end_common' |
| 21 | |
| 22 | def main |
| 23 | STDERR.puts 'start server' |
Alexander Polcyn | 077f890 | 2017-03-24 09:53:40 -0700 | [diff] [blame] | 24 | server_runner = ServerRunner.new(EchoServerImpl) |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 25 | server_port = server_runner.run |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 26 | STDERR.puts 'start client' |
| 27 | _, client_pid = start_client('sig_int_during_channel_watch_client.rb', |
| 28 | server_port) |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 29 | # give time for the client to get into the middle |
| 30 | # of a channel state watch call |
| 31 | sleep 1 |
| 32 | Process.kill('SIGINT', client_pid) |
| 33 | |
| 34 | begin |
| 35 | Timeout.timeout(10) do |
| 36 | Process.wait(client_pid) |
| 37 | end |
| 38 | rescue Timeout::Error |
| 39 | STDERR.puts "timeout wait for client pid #{client_pid}" |
| 40 | Process.kill('SIGKILL', client_pid) |
| 41 | Process.wait(client_pid) |
| 42 | STDERR.puts 'killed client child' |
| 43 | raise 'Timed out waiting for client process. It likely hangs when a ' \ |
| 44 | 'SIGINT is sent while there is an active connectivity_state call' |
| 45 | end |
Alexander Polcyn | 02d131b | 2017-03-22 15:12:32 -0700 | [diff] [blame] | 46 | |
Alexander Polcyn | b2c0b7b | 2017-04-27 00:26:25 -0700 | [diff] [blame] | 47 | client_exit_code = $CHILD_STATUS |
| 48 | if client_exit_code != 0 |
| 49 | fail "sig_int_during_channel_watch_client failed: #{client_exit_code}" |
| 50 | end |
| 51 | |
Alexander Polcyn | 02d131b | 2017-03-22 15:12:32 -0700 | [diff] [blame] | 52 | server_runner.stop |
Alexander Polcyn | ea282e9 | 2017-03-20 20:53:34 -0700 | [diff] [blame] | 53 | end |
| 54 | |
| 55 | main |