forking_client_driver.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env ruby
  2. # Copyright 2016 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. require_relative './end2end_common'
  16. def main
  17. STDERR.puts 'start server'
  18. server_runner = ServerRunner.new(EchoServerImpl)
  19. server_port = server_runner.run
  20. # TODO(apolcyn) Can we get rid of this sleep?
  21. # Without it, an immediate call to the just started EchoServer
  22. # fails with UNAVAILABLE
  23. sleep 1
  24. STDERR.puts 'start client'
  25. _, client_pid = start_client('forking_client_client.rb',
  26. server_port)
  27. begin
  28. Timeout.timeout(10) do
  29. Process.wait(client_pid)
  30. end
  31. rescue Timeout::Error
  32. STDERR.puts "timeout wait for client pid #{client_pid}"
  33. Process.kill('SIGKILL', client_pid)
  34. Process.wait(client_pid)
  35. STDERR.puts 'killed client child'
  36. raise 'Timed out waiting for client process. ' \
  37. 'It likely hangs when requiring grpc, then forking, then using grpc '
  38. end
  39. client_exit_code = $CHILD_STATUS
  40. if client_exit_code != 0
  41. fail "forking client client failed, exit code #{client_exit_code}"
  42. end
  43. server_runner.stop
  44. end
  45. main