• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env ruby
2
3# Copyright 2015 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
19# Test client. Sends RPC's as normal but process also has signal handlers
20class SigHandlingClientController < ClientControl::ClientController::Service
21  def initialize(stub)
22    @stub = stub
23  end
24
25  def do_echo_rpc(req, _)
26    response = @stub.echo(Echo::EchoRequest.new(request: req.request))
27    fail 'bad response' unless response.response == req.request
28    ClientControl::Void.new
29  end
30end
31
32def main
33  client_control_port = ''
34  server_port = ''
35  OptionParser.new do |opts|
36    opts.on('--client_control_port=P', String) do |p|
37      client_control_port = p
38    end
39    opts.on('--server_port=P', String) do |p|
40      server_port = p
41    end
42  end.parse!
43
44  # Allow a few seconds to be safe.
45  srv = new_rpc_server_for_testing
46  srv.add_http2_port("0.0.0.0:#{client_control_port}",
47                     :this_port_is_insecure)
48  stub = Echo::EchoServer::Stub.new("localhost:#{server_port}",
49                                    :this_channel_is_insecure)
50  control_service = SigHandlingClientController.new(stub)
51  srv.handle(control_service)
52  server_thread = Thread.new do
53    srv.run_till_terminated_or_interrupted(['int'])
54  end
55  srv.wait_till_running
56  # send a first RPC to notify the parent process that we've started
57  stub.echo(Echo::EchoRequest.new(request: 'client/child started'))
58  server_thread.join
59end
60
61main
62