Skip to content

Commit cc93b06

Browse files
authored
Fixed a flaky auth integration test by retrying the GetUser() API call a few times with a small delay (#442)
1 parent 2fa81c7 commit cc93b06

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/test/java/com/google/firebase/auth/FirebaseAuthIT.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,20 @@ public void testLastRefreshTime() throws Exception {
336336
// Login to cause the lastRefreshTimestamp to be set.
337337
signInWithPassword(newUserRecord.getEmail(), "password");
338338

339-
UserRecord userRecord = auth.getUser(newUserRecord.getUid());
339+
// Attempt to retrieve the user 3 times (with a small delay between each
340+
// attempt). Occassionally, this call retrieves the user data without the
341+
// lastLoginTime/lastRefreshTime set; possibly because it's hitting a
342+
// different server than the login request uses.
343+
UserRecord userRecord = null;
344+
for (int i = 0; i < 3; i++) {
345+
userRecord = auth.getUser(newUserRecord.getUid());
346+
347+
if (userRecord.getUserMetadata().getLastRefreshTimestamp() != 0) {
348+
break;
349+
}
350+
351+
TimeUnit.SECONDS.sleep((long)Math.pow(2, i));
352+
}
340353

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

0 commit comments

Comments
 (0)