Skip to content

Commit fe3d410

Browse files
authored
Improving stability and speed of intergration tests (firebase#384)
* Adds delay to ensure functions are deployed, adds ability to test node6 and node8 on different projects * Support for 1 or 2 projects, run tests simulatenously when 2 projects * retry deploy up to 3 times, fix typo * Switch to cleaner looping Co-Authored-By: joehan <[email protected]> * code review;
1 parent 616dc4f commit fe3d410

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

integration_test/functions/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export const integrationTests: any = functions
148148
})
149149
.then(() => {
150150
console.log('All tests pass!');
151-
resp.status(200).send('PASS');
151+
resp.status(200).send('PASS \n');
152152
})
153153
.catch(err => {
154154
console.log(`Some tests failed: ${err}`);

integration_test/run_tests.sh

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
set -e
55

66
function usage {
7-
echo "Usage: $0 <project_id>"
7+
echo "Usage: $0 <project_id_node_6> <project_id_node_8>"
88
exit 1
99
}
1010

11+
# This script takes 1 or 2 params, both of which are Firebase project ids.
12+
# If there is only one given, that project will be used for both node6 and node8
13+
# Otherwise, param1 will be used for node6
14+
# and param2 will be used for node8
1115
# The first parameter is required and is the Firebase project id.
1216
if [[ $1 == "" ]]; then
1317
usage
1418
fi
15-
PROJECT_ID=$1
19+
if [[ $2 == "" ]]; then
20+
PROJECT_ID_NODE_6=$1
21+
PROJECT_ID_NODE_8=$1
22+
else
23+
PROJECT_ID_NODE_6=$1
24+
PROJECT_ID_NODE_8=$2
25+
fi
1626

1727
# Directory where this script lives.
1828
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -31,11 +41,13 @@ function build_sdk {
3141

3242
function pick_node6 {
3343
cd $DIR
44+
PROJECT_ID=$PROJECT_ID_NODE_6
3445
cp package.node6.json functions/package.json
3546
}
3647

3748
function pick_node8 {
3849
cd $DIR
50+
PROJECT_ID=$PROJECT_ID_NODE_8
3951
cp package.node8.json functions/package.json
4052
}
4153

@@ -51,15 +63,47 @@ function delete_all_functions {
5163
cd $DIR
5264
# Try to delete, if there are errors it is because the project is already empty,
5365
# in that case do nothing.
54-
firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --project=$PROJECT_ID -f || :
66+
firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_6 || : &
67+
if ! [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then
68+
firebase functions:delete callableTests createUserTests databaseTests deleteUserTests firestoreTests integrationTests pubsubTests remoteConfigTests --force --project=$PROJECT_ID_NODE_8 || : &
69+
fi
70+
wait
5571
announce "Project emptied."
5672
}
5773

5874
function deploy {
5975
cd $DIR
6076
./functions/node_modules/.bin/tsc -p functions/
61-
# Deploy functions, and security rules for database and Firestore
62-
firebase deploy --project=$PROJECT_ID --only functions,database,firestore
77+
# Deploy functions, and security rules for database and Firestore. If the deploy fails, retry twice
78+
for i in 1 2 3; do firebase deploy --project=$PROJECT_ID --only functions,database,firestore && break; done
79+
}
80+
81+
# At the moment, functions take 30-40 seconds AFTER firebase deploy returns successfully to go live
82+
# This needs to be fixed separately
83+
# However, so that we have working integration tests in the interim, waitForPropagation is a workaround
84+
function waitForPropagation {
85+
announce "Waiting 50 seconds for functions changes to propagate"
86+
sleep 50
87+
}
88+
89+
function run_all_tests {
90+
announce "Running the integration tests..."
91+
92+
# Constructs the URLs for both test functions. This may change in the future,
93+
# causing this script to start failing, but currently we don't have a very
94+
# reliable way of determining the URL dynamically.
95+
TEST_DOMAIN="cloudfunctions.net"
96+
if [[ $FIREBASE_FUNCTIONS_URL == "https://preprod-cloudfunctions.sandbox.googleapis.com" ]]; then
97+
TEST_DOMAIN="txcloud.net"
98+
fi
99+
TEST_URL_NODE_6="https://us-central1-$PROJECT_ID_NODE_6.$TEST_DOMAIN/integrationTests"
100+
TEST_URL_NODE_8="https://us-central1-$PROJECT_ID_NODE_8.$TEST_DOMAIN/integrationTests"
101+
echo $TEST_URL_NODE_6
102+
echo $TEST_URL_NODE_8
103+
curl --fail $TEST_URL_NODE_6 & NODE6PID=$!
104+
curl --fail $TEST_URL_NODE_8 & NODE8PID=$!
105+
wait $NODE6PID && echo 'node 6 passed' || (announce 'Node 6 tests failed'; cleanup; announce 'Tests failed'; exit 1)
106+
wait $NODE8PID && echo 'node 8 passed' || (announce 'Node 8 tests failed'; cleanup; announce 'Tests failed'; exit 1)
63107
}
64108

65109
function run_tests {
@@ -93,10 +137,18 @@ install_deps
93137
delete_all_functions
94138
announce "Deploying functions to Node 8 runtime ..."
95139
deploy
96-
run_tests
140+
if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then
141+
waitForPropagation
142+
run_tests
143+
fi
97144
pick_node6
98145
announce "Re-deploying the same functions to Node 6 runtime ..."
99146
deploy
100-
run_tests
147+
waitForPropagation
148+
if [[ $PROJECT_ID_NODE_6 == $PROJECT_ID_NODE_8 ]]; then
149+
run_tests
150+
else
151+
run_all_tests
152+
fi
101153
cleanup
102154
announce "All tests pass!"

0 commit comments

Comments
 (0)