From d2b2889f6fcf27ff5c8a5d74814b6f4efb25b653 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Mon, 14 Jan 2019 12:15:39 -0800 Subject: [PATCH 1/5] Adds delay to ensure functions are deployed, adds ability to test node6 and node8 on different projects --- integration_test/run_tests.sh | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/integration_test/run_tests.sh b/integration_test/run_tests.sh index 05abd2bd6..4fd998b34 100755 --- a/integration_test/run_tests.sh +++ b/integration_test/run_tests.sh @@ -4,15 +4,25 @@ set -e function usage { - echo "Usage: $0 " + echo "Usage: $0 " exit 1 } +# This script takes 1 or 2 params, both of which are Firebase project ids. +# If there is only one given, that project will be used for both node6 and node8 +# Otherwise, param1 will be used for node6 +# and param2 will be used for node8 # The first parameter is required and is the Firebase project id. if [[ $1 == "" ]]; then usage fi -PROJECT_ID=$1 +if [[ $2 == "" ]]; then + PROJECT_ID_NODE_6=$1 + PROJECT_ID_NODE_8=$1 +else + PROJECT_ID_NODE_6=$1 + PROJECT_ID_NODE_8=$2 +fi # Directory where this script lives. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" @@ -31,11 +41,13 @@ function build_sdk { function pick_node6 { cd $DIR + PROJECT_ID=$PROJECT_ID_NODE_6 cp package.node6.json functions/package.json } function pick_node8 { cd $DIR + PROJECT_ID=$PROJECT_ID_NODE_8 cp package.node8.json functions/package.json } @@ -51,7 +63,8 @@ function delete_all_functions { cd $DIR # Try to delete, if there are errors it is because the project is already empty, # in that case do nothing. - firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --project=$PROJECT_ID -f || : + firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_6 || : + firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_8 || : announce "Project emptied." } @@ -62,6 +75,14 @@ function deploy { firebase deploy --project=$PROJECT_ID --only functions,database,firestore } +# At the moment, functions take 30-40 seconds AFTER firebase dpeloy return successfully to go live +# This needs to be fixed separately +# However, so that we have workign integration tests in the interim, waitForPropagation is a workaround +function waitForPropagation { + announce "Waiting 50 seconds for functions changes to propagate" + sleep 50 +} + function run_tests { announce "Running the integration tests..." @@ -91,12 +112,15 @@ build_sdk pick_node8 install_deps delete_all_functions +waitForPropagation announce "Deploying functions to Node 8 runtime ..." deploy +waitForPropagation run_tests pick_node6 announce "Re-deploying the same functions to Node 6 runtime ..." deploy +waitForPropagation run_tests cleanup announce "All tests pass!" From fcbea1c8ca8df610ebeeaee6eafe325d6e5c5fa7 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Mon, 14 Jan 2019 16:24:04 -0800 Subject: [PATCH 2/5] Support for 1 or 2 projects, run tests simulatenously when 2 projects --- integration_test/functions/src/index.ts | 2 +- integration_test/run_tests.sh | 68 +++++++++++++++++++------ 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/integration_test/functions/src/index.ts b/integration_test/functions/src/index.ts index c135b371c..844d8f8da 100644 --- a/integration_test/functions/src/index.ts +++ b/integration_test/functions/src/index.ts @@ -148,7 +148,7 @@ export const integrationTests: any = functions }) .then(() => { console.log('All tests pass!'); - resp.status(200).send('PASS'); + resp.status(200).send('PASS \n'); }) .catch(err => { console.log(`Some tests failed: ${err}`); diff --git a/integration_test/run_tests.sh b/integration_test/run_tests.sh index 4fd998b34..37dfd9339 100755 --- a/integration_test/run_tests.sh +++ b/integration_test/run_tests.sh @@ -63,8 +63,11 @@ function delete_all_functions { cd $DIR # Try to delete, if there are errors it is because the project is already empty, # in that case do nothing. - firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_6 || : - firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_8 || : + firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_6 || : & + if ! [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then + firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_8 || : & + fi + wait announce "Project emptied." } @@ -83,6 +86,26 @@ function waitForPropagation { sleep 50 } +function run_all_tests { + announce "Running the integration tests..." + + # Constructs the URLs for both test functions. This may change in the future, + # causing this script to start failing, but currently we don't have a very + # reliable way of determining the URL dynamically. + TEST_DOMAIN="cloudfunctions.net" + if [[ $FIREBASE_FUNCTIONS_URL == "https://preprod-cloudfunctions.sandbox.googleapis.com" ]]; then + TEST_DOMAIN="txcloud.net" + fi + TEST_URL_NODE_6="https://us-central1-$PROJECT_ID_NODE_6.$TEST_DOMAIN/integrationTests" + TEST_URL_NODE_8="https://us-central1-$PROJECT_ID_NODE_8.$TEST_DOMAIN/integrationTests" + echo $TEST_URL_NODE_6 + echo $TEST_URL_NODE_8 + curl --fail $TEST_URL_NODE_6 & NODE6PID=$! + curl --fail $TEST_URL_NODE_8 & NODE8PID=$! + wait $NODE6PID && echo 'node 6 passed' || (announce 'Node 6 tests failed'; cleanup; announce 'Tests failed'; exit 1) + wait $NODE8PID && echo 'node 8 passed' || (announce 'Node 8 tests failed'; cleanup; announce 'Tests failed'; exit 1) +} + function run_tests { announce "Running the integration tests..." @@ -108,19 +131,32 @@ function cleanup { rm -rf $DIR/functions/node_modules/firebase-functions } -build_sdk -pick_node8 -install_deps -delete_all_functions -waitForPropagation -announce "Deploying functions to Node 8 runtime ..." -deploy -waitForPropagation -run_tests -pick_node6 -announce "Re-deploying the same functions to Node 6 runtime ..." -deploy -waitForPropagation -run_tests +if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then + build_sdk + pick_node8 + install_deps + delete_all_functions + announce "Deploying functions to Node 8 runtime ..." + deploy + waitForPropagation + run_tests + pick_node6 + announce "Re-deploying the same functions to Node 6 runtime ..." + deploy + waitForPropagation + run_tests +else + build_sdk + pick_node8 + install_deps + delete_all_functions + announce "Deploying functions to Node 8 runtime ..." + deploy + pick_node6 + announce "Re-deploying the same functions to Node 6 runtime ..." + deploy + waitForPropagation + run_all_tests +fi cleanup announce "All tests pass!" From 216463434ee6e2eeea9985f57dd6a4152bf55265 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Tue, 15 Jan 2019 13:18:40 -0800 Subject: [PATCH 3/5] retry deploy up to 3 times, fix typo --- integration_test/run_tests.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/integration_test/run_tests.sh b/integration_test/run_tests.sh index 37dfd9339..982d55419 100755 --- a/integration_test/run_tests.sh +++ b/integration_test/run_tests.sh @@ -75,12 +75,14 @@ function deploy { cd $DIR ./functions/node_modules/.bin/tsc -p functions/ # Deploy functions, and security rules for database and Firestore - firebase deploy --project=$PROJECT_ID --only functions,database,firestore + firebase deploy --project=$PROJECT_ID --only functions,database,firestore || \ + firebase deploy --project=$PROJECT_ID --only functions,database,firestore || \ + firebase deploy --project=$PROJECT_ID --only functions,database,firestore ## TODO: try using $() and sed to parse echo to find the printed deploy the rest text } -# At the moment, functions take 30-40 seconds AFTER firebase dpeloy return successfully to go live +# At the moment, functions take 30-40 seconds AFTER firebase deploy returns successfully to go live # This needs to be fixed separately -# However, so that we have workign integration tests in the interim, waitForPropagation is a workaround +# However, so that we have working integration tests in the interim, waitForPropagation is a workaround function waitForPropagation { announce "Waiting 50 seconds for functions changes to propagate" sleep 50 From baa48d5a72c1ee7bf532c6b9078673beda130046 Mon Sep 17 00:00:00 2001 From: Diana Tkachenko <31747099+thechenky@users.noreply.github.com> Date: Tue, 15 Jan 2019 16:35:54 -0800 Subject: [PATCH 4/5] Switch to cleaner looping Co-Authored-By: joehan --- integration_test/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test/run_tests.sh b/integration_test/run_tests.sh index 982d55419..e4a9e4d2d 100755 --- a/integration_test/run_tests.sh +++ b/integration_test/run_tests.sh @@ -77,7 +77,7 @@ function deploy { # Deploy functions, and security rules for database and Firestore firebase deploy --project=$PROJECT_ID --only functions,database,firestore || \ firebase deploy --project=$PROJECT_ID --only functions,database,firestore || \ - firebase deploy --project=$PROJECT_ID --only functions,database,firestore ## TODO: try using $() and sed to parse echo to find the printed deploy the rest text +for i in 1 2 3; do firebase deploy --project=$PROJECT_ID --only functions,database,firestore && break; done } # At the moment, functions take 30-40 seconds AFTER firebase deploy returns successfully to go live From a8f9af9ce30df51dc3dfa9018723fbd7b41dfde5 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Wed, 16 Jan 2019 09:14:11 -0800 Subject: [PATCH 5/5] code review; --- integration_test/run_tests.sh | 42 +++++++++++++---------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/integration_test/run_tests.sh b/integration_test/run_tests.sh index e4a9e4d2d..0e4ffeaa0 100755 --- a/integration_test/run_tests.sh +++ b/integration_test/run_tests.sh @@ -74,10 +74,8 @@ function delete_all_functions { function deploy { cd $DIR ./functions/node_modules/.bin/tsc -p functions/ - # Deploy functions, and security rules for database and Firestore - firebase deploy --project=$PROJECT_ID --only functions,database,firestore || \ - firebase deploy --project=$PROJECT_ID --only functions,database,firestore || \ -for i in 1 2 3; do firebase deploy --project=$PROJECT_ID --only functions,database,firestore && break; done + # Deploy functions, and security rules for database and Firestore. If the deploy fails, retry twice + for i in 1 2 3; do firebase deploy --project=$PROJECT_ID --only functions,database,firestore && break; done } # At the moment, functions take 30-40 seconds AFTER firebase deploy returns successfully to go live @@ -133,31 +131,23 @@ function cleanup { rm -rf $DIR/functions/node_modules/firebase-functions } -if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then - build_sdk - pick_node8 - install_deps - delete_all_functions - announce "Deploying functions to Node 8 runtime ..." - deploy +build_sdk +pick_node8 +install_deps +delete_all_functions +announce "Deploying functions to Node 8 runtime ..." +deploy +if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then waitForPropagation run_tests - pick_node6 - announce "Re-deploying the same functions to Node 6 runtime ..." - deploy - waitForPropagation +fi +pick_node6 +announce "Re-deploying the same functions to Node 6 runtime ..." +deploy +waitForPropagation +if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then run_tests -else - build_sdk - pick_node8 - install_deps - delete_all_functions - announce "Deploying functions to Node 8 runtime ..." - deploy - pick_node6 - announce "Re-deploying the same functions to Node 6 runtime ..." - deploy - waitForPropagation +else run_all_tests fi cleanup