• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# abruptly end a process that has active calls to
18# Channel.watch_connectivity_state
19
20require_relative './end2end_common'
21
22def main
23  STDERR.puts 'start server'
24  echo_service = EchoServerImpl.new
25  server_runner = ServerRunner.new(echo_service)
26  server_port = server_runner.run
27  STDERR.puts 'start client'
28  _, client_pid = start_client('sig_int_during_channel_watch_client.rb',
29                               server_port)
30  # use receipt of one RPC to indicate that the child process is
31  # ready for a SIGINT
32  echo_service.wait_for_first_rpc_received(20)
33  # give time for the client to get into the middle
34  # of a channel state watch call
35  sleep 1
36  Process.kill('SIGINT', client_pid)
37  begin
38    Timeout.timeout(10) do
39      Process.wait(client_pid)
40    end
41  rescue Timeout::Error
42    STDERR.puts "timeout wait for client pid #{client_pid}"
43    Process.kill('SIGKILL', client_pid)
44    Process.wait(client_pid)
45    STDERR.puts 'killed client child'
46    raise 'Timed out waiting for client process. It likely hangs when a ' \
47      'SIGINT is sent while there is an active connectivity_state call'
48  end
49  client_exit_code = $CHILD_STATUS
50  if client_exit_code != 0
51    fail "sig_int_during_channel_watch_client failed: #{client_exit_code}"
52  end
53  server_runner.stop
54end
55
56main
57