xref: /aosp_15_r20/external/grpc-grpc/test/distrib/gcf/python/run_single.sh (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1#!/bin/bash
2# Copyright 2022 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
16cd "$(dirname "$0")"
17
18# Shellcheck cant find the included file.
19# shellcheck disable=SC1091
20source common.sh
21
22set -euxo pipefail
23
24RUNTIME="$1"
25ARTIFACT_URL="$2"
26
27REQUEST_COUNT=20
28LOG_QUIESCE_SECONDS=10
29
30rm -f requirements.txt
31cp requirements.txt.base requirements.txt
32echo "${ARTIFACT_URL}" >>requirements.txt
33
34# Generate Function name.
35FUNCTION_NAME="${FUNCTION_PREFIX}-$(uuidgen)"
36
37function cleanup() {
38  # Wait for logs to quiesce.
39  sleep "${LOG_QUIESCE_SECONDS}"
40  gcloud functions logs read "${FUNCTION_NAME}" || true
41  (yes || true) | gcloud functions delete "${FUNCTION_NAME}"
42}
43
44trap cleanup SIGINT SIGTERM EXIT
45
46# Deploy
47DEPLOY_OUTPUT=$(gcloud functions deploy "${FUNCTION_NAME}" --entry-point test_publish --runtime "${RUNTIME}" --trigger-http --allow-unauthenticated)
48HTTP_URL=$(echo "${DEPLOY_OUTPUT}" | grep "url: " | awk '{print $2;}')
49
50# Send Requests
51for _ in $(seq 1 "${REQUEST_COUNT}"); do
52  GCP_IDENTITY_TOKEN=$(gcloud auth print-identity-token 2>/dev/null);
53  curl -v -H "Authorization: Bearer $GCP_IDENTITY_TOKEN" "${HTTP_URL}"
54done
55