@@ -137,6 +137,8 @@ class FirebaseDatabaseTest : public FirebaseTest {
137137 // Sign in an anonymous user.
138138 static void SignIn ();
139139 // Sign out the current user, if applicable.
140+ // If this is an anonymous user, deletes the user instead,
141+ // to avoid polluting the user list.
140142 static void SignOut ();
141143
142144 // Initialize Firebase Database.
@@ -341,12 +343,19 @@ void FirebaseDatabaseTest::SignOut() {
341343 // Already signed out.
342344 return ;
343345 }
344-
345- shared_auth_->SignOut ();
346-
347- // Wait for the sign-out to finish.
348- while (shared_auth_->current_user () != nullptr ) {
349- if (ProcessEvents (100 )) break ;
346+ if (shared_auth_->current_user ()->is_anonymous ()) {
347+ // If signed in anonymously, delete the anonymous user.
348+ WaitForCompletion (shared_auth_->current_user ()->Delete (), " DeleteAnonymousUser" );
349+ }
350+ else {
351+ // If not signed in anonymously (e.g. if the tests were modified to sign in
352+ // as an actual user), just sign out normally.
353+ shared_auth_->SignOut ();
354+
355+ // Wait for the sign-out to finish.
356+ while (shared_auth_->current_user () != nullptr ) {
357+ if (ProcessEvents (100 )) break ;
358+ }
350359 }
351360 EXPECT_EQ (shared_auth_->current_user (), nullptr );
352361}
@@ -1180,16 +1189,22 @@ TEST_F(FirebaseDatabaseTest, TestInfoConnected) {
11801189 }
11811190 LogDebug (" Disconnecting..." );
11821191 database_->GoOffline ();
1192+ // Pause a moment to give the SDK time to realize we are disconnected.
1193+ ProcessEvents (1000 );
11831194 {
11841195 auto disconnected = info.GetValue ();
11851196 WaitForCompletion (disconnected, " GetValue 3" );
11861197 EXPECT_EQ (disconnected.result ()->value (), false );
11871198 }
11881199 LogDebug (" Reconnecting..." );
11891200 database_->GoOnline ();
1201+ // Pause a moment to give the SDK time to realize we are reconnected.
11901202 ProcessEvents (1000 );
11911203 // Force getting a value so that we reconnect to the database.
11921204 WaitForCompletion (ref.GetValue (), " GetValue 4 [ignored]" );
1205+ // Pause another moment to REALLY give the SDK time to realize we are
1206+ // reconnected.
1207+ ProcessEvents (1000 );
11931208 {
11941209 auto reconnected = info.GetValue ();
11951210 WaitForCompletion (reconnected, " GetValue 5" );
0 commit comments