Skip to content

Conversation

@rjhuijsman
Copy link
Contributor

Make the integration test fully-automatic. This entails two major changes:

  • In the HTTP Cloud Function that sets off the server-side part of the test, keep track of which tests pass, and return 200 "PASS" when all tests pass, or 500 "FAIL - [debug-info]" when they don't.
  • On the client-side, automatically trigger that HTTP function and interpret the return code as a pass or fail.

Also tries to improve the readability of 'run_tests.sh' by indenting appropriately, and tries to improve its usability by more clearly indicating whether the tests have passed or failed.

This entails two major changes:
- In the Cloud Functions, keep track of which tests pass, and return 200 "PASS" when all tests pass, or 500 "FAIL - [debug-info]" when they don't.
- On the client-side, trigger the HTTP function and interpret the return code as a pass or fail.

Also tries to improve the readability of 'run_tests.sh' by indenting appropriately, and improve the usability by more clearly indicating whether tests have passed or failed.
@rjhuijsman rjhuijsman force-pushed the rjh.auto-integration-test branch from e0d95ab to 39caf7c Compare July 27, 2017 04:37
export * from './pubsub-tests';
export * from './database-tests';
export * from './auth-tests';
let numTests = 4; // Make sure to increase this as you add tests!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of hardcoding this, I'd recommend naming the array of promises, then setting numTests to the length of that array. Then the next developer doesn't have to change this number if they add tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are not actually not quite the same as the number of promises, but they are the same as the number of exported functions - so I've gone off that. :)

echo "##### Deploying empty index.js to project..." &&
./functions/node_modules/.bin/tsc -p functions/ && # Make sure the functions/lib directory actually exists.
echo "" > functions/lib/index.js &&
firebase deploy --debug 2> /dev/null &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably also put --only functions here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

echo "##### Removing all functions" &&
echo "" > functions/lib/index.js &&
firebase deploy --debug 2> /dev/null &&
rm functions/firebase-functions.tgz &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also add a line to remove firebase-debug.log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@laurenzlong
Copy link
Contributor

Biggest piece of feedback is that when something fails, it just prints out XXXXX Something failed XXXXXXX

It should at the minimum print out the URL for the database so the user can go check what's wrong.

(PS. you can easily simulate a failure by changing one of the promises in functions/index.ts to RSVP.reject())

failedintegration

@laurenzlong laurenzlong assigned rjhuijsman and unassigned inlined and laurenzlong Jul 27, 2017
- In index.ts, automatically compute the number of tests, rather than hardcoding it.
- In index.ts, return a useful error message if any promise fails, not just if tests fail.
- In run_tests.sh, always deploy only functions.
- In run_tests.sh, clean up firebase-debug.log.
@rjhuijsman
Copy link
Contributor Author

Good catch that that type of failure got less logs than they should - I've rejiggered the promises in index.ts so that those failures are also caught and logged with error-500.

@rjhuijsman rjhuijsman assigned inlined and laurenzlong and unassigned rjhuijsman Jul 28, 2017
Copy link
Contributor

@laurenzlong laurenzlong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one quick fix (add a space), then it's good to merge.

firebase deploy --debug 2> /dev/null &&
echo &&
firebase deploy --only functions --debug 2> /dev/null &&
echo &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing one space here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@rjhuijsman rjhuijsman merged commit bec9f05 into master Jul 28, 2017
@rjhuijsman rjhuijsman deleted the rjh.auto-integration-test branch July 28, 2017 23:20
// On test completion, redirect the user to the Firebase RTDB dashboard, to
// see the results stored there.
resp.redirect(`https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}`);
// On test completion, check that all tests pass and reply "PASS", or provide further details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we may want to break this into client + server. The HTTP function could return the test ID and then a client would poll for the ID. This would help us avoid stricter cutoffs in maximum HTTP request duration.

ref.on('child_added', (snapshot) => {
testsExecuted += 1;
if (!snapshot.val().passed) {
reject(new Error(`test ${snapshot.key} failed; see database for details.`));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a link?

});
}).then(() => {
ref.off(); // No more need to listen.
return Promise.resolve();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary

resp.status(200).send('PASS');
}).catch(err => {
console.log(`Some tests failed: ${err}`);
resp.status(500).send(`FAIL - details at https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits:

  1. the GCLOUD_PROJECT is not necessarily the subdomain to firebaseio.com; you can use functions.config().firebase.databaseUrl.
  2. I think the URL has to end in .json if you're linking to a database URL.
  3. You might actually want to consider a pantheon so it will try to load the database using the developer credentials rather than unauthenticated credentials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants