interop_test.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. #
  3. # Copyright 2019 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. set -e +x
  18. export TMPDIR=$(mktemp -d)
  19. trap "rm -rf ${TMPDIR}" EXIT
  20. clean () {
  21. for i in {1..10}; do
  22. jobs -p | xargs -n1 pkill -P
  23. # A simple "wait" just hangs sometimes. Running `jobs` seems to help.
  24. sleep 1
  25. if jobs | read; then
  26. return
  27. fi
  28. done
  29. echo "$(tput setaf 1) clean failed to kill tests $(tput sgr 0)"
  30. jobs
  31. pstree
  32. exit 1
  33. }
  34. fail () {
  35. echo "$(tput setaf 1) $1 $(tput sgr 0)"
  36. clean
  37. exit 1
  38. }
  39. pass () {
  40. echo "$(tput setaf 2) $1 $(tput sgr 0)"
  41. }
  42. # Don't run some tests that need a special environment:
  43. # "google_default_credentials"
  44. # "compute_engine_channel_credentials"
  45. # "compute_engine_creds"
  46. # "service_account_creds"
  47. # "jwt_token_creds"
  48. # "oauth2_auth_token"
  49. # "per_rpc_creds"
  50. # "pick_first_unary"
  51. CASES=(
  52. "empty_unary"
  53. "large_unary"
  54. "client_streaming"
  55. "server_streaming"
  56. "ping_pong"
  57. "empty_stream"
  58. "timeout_on_sleeping_server"
  59. "cancel_after_begin"
  60. "cancel_after_first_response"
  61. "status_code_and_message"
  62. "special_status_message"
  63. "custom_metadata"
  64. "unimplemented_method"
  65. "unimplemented_service"
  66. )
  67. # Build server
  68. if ! go build -o /dev/null ./interop/server; then
  69. fail "failed to build server"
  70. else
  71. pass "successfully built server"
  72. fi
  73. # Start server
  74. SERVER_LOG="$(mktemp)"
  75. go run ./interop/server --use_tls &> $SERVER_LOG &
  76. for case in ${CASES[@]}; do
  77. echo "$(tput setaf 4) testing: ${case} $(tput sgr 0)"
  78. CLIENT_LOG="$(mktemp)"
  79. if ! timeout 20 go run ./interop/client --use_tls --server_host_override=foo.test.google.fr --use_test_ca --test_case="${case}" &> $CLIENT_LOG; then
  80. fail "FAIL: test case ${case}
  81. got server log:
  82. $(cat $SERVER_LOG)
  83. got client log:
  84. $(cat $CLIENT_LOG)
  85. "
  86. else
  87. pass "PASS: test case ${case}"
  88. fi
  89. done
  90. clean