http2_server_health_check.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright 2017 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import argparse
  15. import sys
  16. import hyper
  17. # Utility to healthcheck the http2 server. Used when starting the server to
  18. # verify that the server is live before tests begin.
  19. if __name__ == '__main__':
  20. parser = argparse.ArgumentParser()
  21. parser.add_argument('--server_host', type=str, default='localhost')
  22. parser.add_argument('--server_port', type=int, default=8080)
  23. args = parser.parse_args()
  24. server_host = args.server_host
  25. server_port = args.server_port
  26. conn = hyper.HTTP20Connection('%s:%d' % (server_host, server_port))
  27. conn.request('POST', '/grpc.testing.TestService/UnaryCall')
  28. resp = conn.get_response()
  29. if resp.headers.get('grpc-encoding') is None:
  30. sys.exit(1)
  31. else:
  32. sys.exit(0)