run-interop-tests.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. ## Copyright 2024, gRPC Authors All rights reserved.
  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. set -euo pipefail
  16. log() { printf -- "** %s\n" "$*" >&2; }
  17. error() { printf -- "** ERROR: %s\n" "$*" >&2; }
  18. fatal() { error "$@"; exit 1; }
  19. here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  20. build_flags=(
  21. "--package-path" "$here/../IntegrationTests/grpc-interop-tests"
  22. "-c" "release"
  23. )
  24. # Build the executable
  25. log "Building gRPC interop tests..."
  26. if ! swift build "${build_flags[@]}"; then
  27. fatal "Build failed"
  28. fi
  29. # Grab the path to the executable.
  30. interop_tests_bin=$(swift build "${build_flags[@]}" --show-bin-path)/grpc-interop-tests
  31. # Start the server. Capture unbuffered stdout otherwise it might not have been
  32. # written to when we read the port.
  33. server_output_file=$(mktemp)
  34. host="127.0.0.1"
  35. port="0"
  36. stdbuf -o0 "$interop_tests_bin" start-server \
  37. --host "$host" \
  38. --port "$port" \
  39. > "$server_output_file" 2>&1 &
  40. server_pid=$!
  41. # Give the server a moment to start up.
  42. sleep 1
  43. # Extract the port number that the server bound to. Capture the whole string
  44. # then narrow it down to just the port.
  45. pattern="listening address: \[ipv4\]$host:[0-9]*$"
  46. bound_port=$(grep -o "$pattern" < "$server_output_file" | grep -o '[0-9]*$')
  47. if [[ -z "$bound_port" ]]; then
  48. error "Failed to get the bound port."
  49. kill $server_pid # ignore-unacceptable-language
  50. exit 1
  51. else
  52. log "Started server on $host:$bound_port"
  53. fi
  54. # Now run the tests, keeping track of failures.
  55. failed_tests=0
  56. tests=(
  57. empty_unary
  58. large_unary
  59. client_compressed_unary
  60. server_compressed_unary
  61. client_streaming
  62. server_streaming
  63. server_compressed_streaming
  64. ping_pong
  65. empty_stream
  66. custom_metadata
  67. status_code_and_message
  68. special_status_message
  69. unimplemented_method
  70. unimplemented_service
  71. )
  72. for test in "${tests[@]}"; do
  73. # The executable prints the running test and result, don't duplicate that in
  74. # logs here.
  75. if ! $interop_tests_bin run-tests --host "$host" --port "$bound_port" "$test"; then
  76. ((failed_tests++))
  77. fi
  78. done
  79. # Stop the server
  80. log "Stopping the server..."
  81. kill $server_pid # ignore-unacceptable-language
  82. if [[ $failed_tests -gt 0 ]]; then
  83. error "$failed_tests tests failed."
  84. exit 1
  85. else
  86. log "All tests passed."
  87. exit 0
  88. fi