Skip to content

Commit

Permalink
fix(testing): ensure resource cleanup happens on GAE and Cloud Run te…
Browse files Browse the repository at this point in the history
…sts (#1683)

Fixes #1682. Follow-up to #1634 

Integration with buildcop bot clobbered existing test cleanup process for Cloud Run and App Engine.
  • Loading branch information
grayside authored Mar 31, 2020
1 parent 0822b53 commit 72631ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
24 changes: 11 additions & 13 deletions .kokoro/build-with-appengine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,21 @@ VERSION=$(echo $VERSION | sed 's_/flexible\|/standard__')
export GAE_VERSION=$VERSION
export GCLOUD_STORAGE_BUCKET=docs-samples-${VERSION}

# Register post-test cleanup
function cleanup {
gcloud app versions delete $GAE_VERSION --quiet
}
trap cleanup EXIT


cd github/nodejs-docs-samples/${PROJECT}


# Configure gcloud
export GOOGLE_APPLICATION_CREDENTIALS=${KOKORO_GFILE_DIR}/secrets-key.json
gcloud auth activate-service-account --key-file "$GOOGLE_APPLICATION_CREDENTIALS"
gcloud config set project $GCLOUD_PROJECT


# Deploy the app
gcloud app deploy --version $GAE_VERSION --no-promote --quiet

# Register post-test cleanup
function cleanup {
gcloud app versions delete $GAE_VERSION --quiet
}
trap cleanup EXIT HUP

# Install dependencies and run tests
npm install
Expand All @@ -69,11 +65,13 @@ npm install
# to open issues on failures:
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"release"* ]]; then
export MOCHA_REPORTER_SUITENAME=${PROJECT}
cleanup() {
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
notify_buildcop() {
# Call the original trap function.
cleanup
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
}
trap cleanup EXIT HUP
trap notify_buildcop EXIT HUP
fi

npm test
Expand Down
22 changes: 12 additions & 10 deletions .kokoro/build-with-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ SUFFIX=${KOKORO_BUILD_ID}
export SERVICE_NAME="${SAMPLE_NAME}-${SUFFIX}"
export CONTAINER_IMAGE="gcr.io/${GOOGLE_CLOUD_PROJECT}/run-${SAMPLE_NAME}:${SAMPLE_VERSION}"

# Register post-test cleanup.
function cleanup {
gcloud --quiet container images delete "${CONTAINER_IMAGE}" || true
}
trap cleanup EXIT

# Build the service
set -x
gcloud builds submit --tag="${CONTAINER_IMAGE}"
set +x

# Register post-test cleanup.
function cleanup {
gcloud --quiet container images delete "${CONTAINER_IMAGE}" || true
}
trap cleanup EXIT HUP

# Install dependencies and run Nodejs tests.
export NODE_ENV=development
npm install
Expand All @@ -65,11 +65,13 @@ npm install
# to open issues on failures:
if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"release"* ]]; then
export MOCHA_REPORTER_SUITENAME=${PROJECT}
cleanup() {
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
notify_buildcop() {
# Call the original trap function.
cleanup
chmod +x $KOKORO_GFILE_DIR/linux_amd64/buildcop
$KOKORO_GFILE_DIR/linux_amd64/buildcop
}
trap cleanup EXIT HUP
trap notify_buildcop EXIT HUP
fi

npm test
Expand Down

0 comments on commit 72631ea

Please sign in to comment.