Debian Codegraph @

test/distrib/gcf/python/run_single.sh

raw
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
16 cd "$(dirname "$0")"
17
18 # Shellcheck cant find the included file.
19 # shellcheck disable=SC1091
20 source common.sh
21
22 set -euxo pipefail
23
24 RUNTIME="$1"
25 ARTIFACT_URL="$2"
26
27 REQUEST_COUNT=20
28 LOG_QUIESCE_SECONDS=10
29
30 rm -f requirements.txt
31 cp requirements.txt.base requirements.txt
32 echo "${ARTIFACT_URL}" >>requirements.txt
33
34 # Generate Function name.
35 FUNCTION_NAME="${FUNCTION_PREFIX}-$(uuidgen)"
36
37 function 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
44 trap cleanup SIGINT SIGTERM EXIT
45
46 # Deploy
47 DEPLOY_OUTPUT=$(gcloud functions deploy "${FUNCTION_NAME}" --entry-point test_publish --runtime "${RUNTIME}" --trigger-http --allow-unauthenticated)
48 HTTP_URL=$(echo "${DEPLOY_OUTPUT}" | grep "url: " | awk '{print $2;}')
49
50 # Send Requests
51 for _ 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}"
54 done