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

Fixed a flaky auth integration test by retrying the GetUser() API call #907

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 23 additions & 6 deletions test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,29 @@ describe('admin.auth', () => {

// Login to set the lastRefreshTime.
await firebase.auth!().signInWithEmailAndPassword('lastRefreshTimeUser@example.com', 'p4ssword')
.then(() => admin.auth().getUser('lastRefreshTimeUser'))
.then((userRecord) => {
expect(userRecord.metadata.lastRefreshTime).to.exist;
expect(isUTCString(userRecord.metadata.lastRefreshTime!));
const creationTime = new Date(userRecord.metadata.creationTime).getTime();
const lastRefreshTime = new Date(userRecord.metadata.lastRefreshTime!).getTime();
.then(async () => {
// Attempt to retrieve the user 3 times (with a small delay between
// each attempt). Occassionally, this call retrieves the user data
// without the lastLoginTime/lastRefreshTime set; possibly because
// it's hitting a different server than the login request uses.
let userRecord = null;

for (let i = 0; i < 3; i++) {
userRecord = await admin.auth().getUser('lastRefreshTimeUser');
if (userRecord.metadata.lastRefreshTime) {
break;
}

await new Promise((resolve) => {
setTimeout(resolve, 1000 * Math.pow(2, i));
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

const metadata = userRecord!.metadata;

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

const metadata = userRecord!.metadata;
expect(metadata.lastRefreshTime).to.exist;
expect(isUTCString(metadata.lastRefreshTime!));
const creationTime = new Date(metadata.creationTime).getTime();
const lastRefreshTime = new Date(metadata.lastRefreshTime!).getTime();
expect(creationTime).lte(lastRefreshTime);
expect(lastRefreshTime).lte(creationTime + 3600 * 1000);
});
Expand Down