Skip to content

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

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

Merged
merged 1 commit into from
Jun 16, 2020
Merged
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
15 changes: 14 additions & 1 deletion src/test/java/com/google/firebase/auth/FirebaseAuthIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,20 @@ public void testLastRefreshTime() throws Exception {
// Login to cause the lastRefreshTimestamp to be set.
signInWithPassword(newUserRecord.getEmail(), "password");

UserRecord userRecord = auth.getUser(newUserRecord.getUid());
// 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.
UserRecord userRecord = null;
for (int i = 0; i < 3; i++) {
userRecord = auth.getUser(newUserRecord.getUid());

if (userRecord.getUserMetadata().getLastRefreshTimestamp() != 0) {
break;
}

TimeUnit.SECONDS.sleep((long)Math.pow(2, i));
}

// Ensure the lastRefreshTimestamp is approximately "now" (with a tollerance of 10 minutes).
long now = System.currentTimeMillis();
Expand Down