Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(testing): ensure resource cleanup happens on GAE and Cloud Run tests #1683

Merged
merged 4 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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