Skip to content

Commit 9828658

Browse files
authored
Fixed a flaky auth integration test by retrying the GetUser() API call (#197)
1 parent d5a7a3f commit 9828658

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

FirebaseAdmin/FirebaseAdmin.IntegrationTests/FirebaseAuthTest.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,22 @@ public async Task LastRefreshTime()
352352
// Login to cause the LastRefreshTimestamp to be set.
353353
await SignInWithPasswordAsync(newUserRecord.Email, "password");
354354

355-
var userRecord = await FirebaseAuth.DefaultInstance.GetUserAsync(newUserRecord.Uid);
355+
// Attempt to retrieve the user 3 times (with a small delay between each attempt).
356+
// Occassionally, this call retrieves the user data without the
357+
// lastLoginTime/lastRefreshTime set; possibly because it's hitting a different
358+
// server than the login request uses.
359+
UserRecord userRecord = null;
360+
for (int i = 0; i < 3; i++)
361+
{
362+
userRecord = await FirebaseAuth.DefaultInstance.GetUserAsync(newUserRecord.Uid);
363+
364+
if (userRecord.UserMetaData.LastRefreshTimestamp != null)
365+
{
366+
break;
367+
}
368+
369+
await Task.Delay(1000 * (int)Math.Pow(2, i));
370+
}
356371

357372
// Ensure the LastRefreshTimstamp is approximately "now" (with a tollerance of 10 minutes).
358373
var now = DateTime.UtcNow;

0 commit comments

Comments
 (0)