Skip to content

Commit 59ddbce

Browse files
authored
Firestore: disable debug logging in integration tests (#1024)
1 parent 63e6549 commit 59ddbce

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

firestore/integration_test_internal/src/firestore_integration_test.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,10 @@ Firestore* FirestoreIntegrationTest::TestFirestoreWithProjectId(
149149
apps_[app] = std::unique_ptr<App>(app);
150150
}
151151

152-
// Firestore::set_log_level(LogLevel::kLogLevelDebug);
153-
154152
Firestore* db = new Firestore(CreateTestFirestoreInternal(app));
155153
firestores_[db] = FirestoreInfo(name, std::unique_ptr<Firestore>(db));
156154

157155
LocateEmulator(db);
158-
InitializeFirestore(db);
159156
return db;
160157
}
161158

firestore/integration_test_internal/src/firestore_integration_test.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const int kCheckIntervalMillis = 100;
4848
const int kTimeOutMillis = 15000;
4949

5050
FirestoreInternal* CreateTestFirestoreInternal(App* app);
51-
void InitializeFirestore(Firestore* instance);
5251

5352
App* GetApp();
5453
App* GetApp(const char* name, const std::string& override_project_id);
@@ -175,6 +174,27 @@ class TestEventListener {
175174
bool print_debug_info_ = false;
176175
};
177176

177+
// A RAII wrapper that enables Firestore debug logging and then disables it
178+
// upon destruction.
179+
//
180+
// This is useful for enabling Firestore debug logging in a specific test.
181+
//
182+
// Example:
183+
// TEST(MyCoolTest, VerifyFirestoreDoesItsThing) {
184+
// FirestoreDebugLogEnabler firestore_debug_log_enabler;
185+
// ...
186+
// }
187+
class FirestoreDebugLogEnabler {
188+
public:
189+
FirestoreDebugLogEnabler() {
190+
Firestore::set_log_level(LogLevel::kLogLevelDebug);
191+
}
192+
193+
~FirestoreDebugLogEnabler() {
194+
Firestore::set_log_level(LogLevel::kLogLevelInfo);
195+
}
196+
};
197+
178198
// Base class for Firestore integration tests.
179199
// Note it keeps a cache of created Firestore instances, and is thread-unsafe.
180200
class FirestoreIntegrationTest : public testing::Test {

firestore/integration_test_internal/src/listener_registration_test.cc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,7 @@
3434
namespace firebase {
3535
namespace firestore {
3636

37-
using ListenerRegistrationCommonTest = testing::Test;
38-
39-
class ListenerRegistrationTest : public FirestoreIntegrationTest {
40-
public:
41-
ListenerRegistrationTest() {
42-
// TestFirestore()->set_log_level(LogLevel::kLogLevelDebug);
43-
}
44-
};
37+
using ListenerRegistrationTest = FirestoreIntegrationTest;
4538

4639
TEST_F(ListenerRegistrationTest, TestCanBeRemoved) {
4740
CollectionReference collection = Collection();
@@ -136,7 +129,7 @@ TEST_F(ListenerRegistrationTest, TestCanBeRemovedIndependently) {
136129
// The most valuable test is making sure that a copy of a registration can be
137130
// used to remove the listener.
138131

139-
TEST_F(ListenerRegistrationCommonTest, Construction) {
132+
TEST_F(ListenerRegistrationTest, Construction) {
140133
auto* internal = testutil::NewInternal<ListenerRegistrationInternal>();
141134
auto registration = MakePublic<ListenerRegistration>(internal);
142135
EXPECT_EQ(internal, GetInternal(registration));
@@ -155,7 +148,7 @@ TEST_F(ListenerRegistrationCommonTest, Construction) {
155148
delete internal;
156149
}
157150

158-
TEST_F(ListenerRegistrationCommonTest, Assignment) {
151+
TEST_F(ListenerRegistrationTest, Assignment) {
159152
auto* internal = testutil::NewInternal<ListenerRegistrationInternal>();
160153
auto registration = MakePublic<ListenerRegistration>(internal);
161154
ListenerRegistration reg_copy;
@@ -171,7 +164,7 @@ TEST_F(ListenerRegistrationCommonTest, Assignment) {
171164
delete internal;
172165
}
173166

174-
TEST_F(ListenerRegistrationCommonTest, Remove) {
167+
TEST_F(ListenerRegistrationTest, Remove) {
175168
auto* internal = testutil::NewInternal<ListenerRegistrationInternal>();
176169
auto registration = MakePublic<ListenerRegistration>(internal);
177170
ListenerRegistration reg_copy;

firestore/integration_test_internal/src/numeric_transforms_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class NumericTransformsTest : public FirestoreIntegrationTest {
126126
};
127127

128128
TEST_F(NumericTransformsTest, CreateDocumentWithIncrement) {
129+
// TODO(dconeybe) Remove the FirestoreDebugLogEnabler on the line below once
130+
// this test's flakiness is solved.
131+
FirestoreDebugLogEnabler debug_log_enabler;
129132
Await(doc_ref_.Set({{"sum", FieldValue::Increment(1337)}}));
130133

131134
ExpectLocalAndRemoteValue(1337);

firestore/integration_test_internal/src/transaction_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,10 @@ TEST_F(TransactionTest, TestCancellationOnError) {
732732
}
733733

734734
TEST_F(TransactionTest, TestMaxAttempts) {
735+
// TODO(dconeybe) Remove the FirestoreDebugLogEnabler on the line below once
736+
// this test's flakiness is solved.
737+
FirestoreDebugLogEnabler firestore_debug_log_enabler;
738+
735739
Firestore* firestore = TestFirestore();
736740
DocumentReference doc = firestore->Collection("TestMaxAttempts").Document();
737741

firestore/integration_test_internal/src/type_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class TypeTest : public FirestoreIntegrationTest {
3030
// Write the specified data to Firestore as a document and read that document.
3131
// Check the data read from that document matches with the original data.
3232
void AssertSuccessfulRoundTrip(MapFieldValue data) {
33-
// TestFirestore()->set_log_level(LogLevel::kLogLevelDebug);
3433
DocumentReference reference = Document();
3534
WriteDocument(reference, data);
3635
DocumentSnapshot snapshot = ReadDocument(reference);

firestore/integration_test_internal/src/util/integration_test_util.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,5 @@ FirestoreInternal* CreateTestFirestoreInternal(App* app) {
8181
return TestFriend::CreateTestFirestoreInternal(app);
8282
}
8383

84-
void InitializeFirestore(Firestore* instance) {
85-
Firestore::set_log_level(LogLevel::kLogLevelDebug);
86-
}
87-
8884
} // namespace firestore
8985
} // namespace firebase

0 commit comments

Comments
 (0)