Skip to content

Commit 3ea7a5f

Browse files
authored
Modify integration tests so that they delete the anonymous user they created.
This prevents us from leaving a ton of defunct anonymous users in the project for no reason.
1 parent 9261821 commit 3ea7a5f

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

database/integration_test/src/integration_test.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

firestore/integration_test/src/integration_test.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class FirebaseFirestoreBasicTest : public FirebaseTest {
7676
// Sign in an anonymous user.
7777
static void SignIn();
7878
// Sign out the current user, if applicable.
79+
// If this is an anonymous user, deletes the user instead,
80+
// to avoid polluting the user list.
7981
static void SignOut();
8082

8183
// Initialize Firestore.
@@ -282,11 +284,19 @@ void FirebaseFirestoreBasicTest::SignOut() {
282284
return;
283285
}
284286

285-
shared_auth_->SignOut();
286-
287-
// Wait for the sign-out to finish.
288-
while (shared_auth_->current_user() != nullptr) {
289-
if (ProcessEvents(100)) break;
287+
if (shared_auth_->current_user()->is_anonymous()) {
288+
// If signed in anonymously, delete the anonymous user.
289+
WaitForCompletion(shared_auth_->current_user()->Delete(), "DeleteAnonymousUser");
290+
}
291+
else {
292+
// If not signed in anonymously (e.g. if the tests were modified to sign in
293+
// as an actual user), just sign out normally.
294+
shared_auth_->SignOut();
295+
296+
// Wait for the sign-out to finish.
297+
while (shared_auth_->current_user() != nullptr) {
298+
if (ProcessEvents(100)) break;
299+
}
290300
}
291301
EXPECT_EQ(shared_auth_->current_user(), nullptr);
292302
}

storage/integration_test/src/integration_test.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class FirebaseStorageTest : public FirebaseTest {
8787
// Sign in an anonymous user.
8888
static void SignIn();
8989
// Sign out the current user, if applicable.
90+
// If this is an anonymous user, deletes the user instead,
91+
// to avoid polluting the user list.
9092
static void SignOut();
9193

9294
// Initialize Firebase Storage.
@@ -279,10 +281,19 @@ void FirebaseStorageTest::SignOut() {
279281
// Already signed out.
280282
return;
281283
}
282-
shared_auth_->SignOut();
283-
// Wait for the sign-out to finish.
284-
while (shared_auth_->current_user() != nullptr) {
285-
if (ProcessEvents(100)) break;
284+
if (shared_auth_->current_user()->is_anonymous()) {
285+
// If signed in anonymously, delete the anonymous user.
286+
WaitForCompletion(shared_auth_->current_user()->Delete(), "DeleteAnonymousUser");
287+
}
288+
else {
289+
// If not signed in anonymously (e.g. if the tests were modified to sign in
290+
// as an actual user), just sign out normally.
291+
shared_auth_->SignOut();
292+
293+
// Wait for the sign-out to finish.
294+
while (shared_auth_->current_user() != nullptr) {
295+
if (ProcessEvents(100)) break;
296+
}
286297
}
287298
EXPECT_EQ(shared_auth_->current_user(), nullptr);
288299
}

0 commit comments

Comments
 (0)