Skip to content

Commit 9ce45e7

Browse files
committed
fix unit test
1 parent 7cc04c5 commit 9ce45e7

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

firebase-perf/src/test/java/com/google/firebase/perf/FirebasePerformanceTestBase.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
import com.google.firebase.perf.config.ConfigResolver;
2626
import com.google.firebase.perf.session.PerfSession;
2727
import com.google.firebase.perf.session.SessionManager;
28+
import com.google.firebase.perf.session.gauges.GaugeCounter;
2829
import com.google.firebase.perf.util.ImmutableBundle;
2930
import org.junit.After;
3031
import org.junit.Before;
31-
import org.robolectric.shadows.ShadowLog;
32+
import org.junit.BeforeClass;
3233
import org.robolectric.shadows.ShadowPackageManager;
3334

3435
public class FirebasePerformanceTestBase {
36+
3537
/**
3638
* The following values are needed by Firebase to identify the project and application that all
3739
* data stored in Firebase databases gets associated with. This is important to determine data
@@ -54,9 +56,14 @@ public class FirebasePerformanceTestBase {
5456

5557
protected Context appContext;
5658

59+
@BeforeClass
60+
public static void setUpBeforeClass() {
61+
// TODO(b/394127311): Explore removing this.
62+
GaugeCounter.INSTANCE.resetCounter();
63+
}
64+
5765
@Before
5866
public void setUpFirebaseApp() {
59-
ShadowLog.stream = System.out;
6067
appContext = ApplicationProvider.getApplicationContext();
6168

6269
ShadowPackageManager shadowPackageManager = shadowOf(appContext.getPackageManager());

firebase-perf/src/test/java/com/google/firebase/perf/session/gauges/GaugeManagerTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public void setUp() {
130130
@After
131131
public void tearDown() {
132132
shadowOf(Looper.getMainLooper()).idle();
133-
GaugeCounter.INSTANCE.resetCounter();
134133
}
135134

136135
@Test
@@ -332,11 +331,11 @@ public void stopCollectingGauges_invalidGaugeCollectionFrequency_appInForeground
332331
}
333332

334333
@Test
335-
public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
334+
public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() throws InterruptedException {
336335
PerfSession fakeSession = createTestSession(1);
337336
testGaugeManager.setApplicationProcessState(ApplicationProcessState.FOREGROUND);
338337
testGaugeManager.startCollectingGauges(fakeSession);
339-
GaugeCounter.setGaugeManager(testGaugeManager);
338+
GaugeCounter.INSTANCE.setGaugeManager(testGaugeManager);
340339

341340
// There's no job to log the gauges.
342341
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
@@ -378,7 +377,7 @@ public void testUpdateAppStateHandlesMultipleAppStates() {
378377
fakeSession.setGaugeAndEventCollectionEnabled(true);
379378
testGaugeManager.setApplicationProcessState(ApplicationProcessState.FOREGROUND);
380379
testGaugeManager.startCollectingGauges(fakeSession);
381-
GaugeCounter.setGaugeManager(testGaugeManager);
380+
GaugeCounter.INSTANCE.setGaugeManager(testGaugeManager);
382381

383382
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
384383
generateMetricsAndIncrementCounter(10);
@@ -430,7 +429,7 @@ public void testGaugeManagerHandlesMultipleSessionIds() {
430429
fakeSession.setGaugeAndEventCollectionEnabled(true);
431430
testGaugeManager.setApplicationProcessState(ApplicationProcessState.BACKGROUND);
432431
testGaugeManager.startCollectingGauges(fakeSession);
433-
GaugeCounter.setGaugeManager(testGaugeManager);
432+
GaugeCounter.INSTANCE.setGaugeManager(testGaugeManager);
434433

435434
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
436435
generateMetricsAndIncrementCounter(10);
@@ -520,7 +519,7 @@ public void testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics(
520519
+ recordedGaugeMetric.getCpuMetricReadingsCount();
521520
assertThat(recordedGaugeMetricsCount).isEqualTo(2);
522521

523-
// TODO(b/394127311): Investigate why this isn't 0.
522+
// TODO(b/394127311): Investigate why this isn't 0 on local runs.
524523
// assertThat(GaugeCounter.INSTANCE.count()).isEqualTo(0);
525524
}
526525

0 commit comments

Comments
 (0)