Skip to content

Commit 75929f3

Browse files
committed
Add test for decrement
1 parent 4e5773b commit 75929f3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,36 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() throws Inte
371371
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
372372
}
373373

374+
@Test
375+
public void testGaugeCounterIsDecrementedWhenLogged() throws InterruptedException {
376+
int priorGaugeCounter = GaugeCounter.count();
377+
378+
PerfSession fakeSession = createTestSession(1);
379+
testGaugeManager.setApplicationProcessState(ApplicationProcessState.FOREGROUND);
380+
testGaugeManager.startCollectingGauges(fakeSession);
381+
GaugeCounter.setGaugeManager(testGaugeManager);
382+
383+
// There's no job to log the gauges.
384+
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
385+
386+
// Generate metrics that don't exceed the GaugeCounter.MAX_COUNT.
387+
generateMetricsAndIncrementCounter(20);
388+
389+
// There's still no job to log the gauges.
390+
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
391+
392+
generateMetricsAndIncrementCounter(10);
393+
394+
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
395+
assertThat(fakeScheduledExecutorService.getDelayToNextTask(TimeUnit.MILLISECONDS))
396+
.isEqualTo(TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS);
397+
398+
assertThat(GaugeCounter.count()).isEqualTo(priorGaugeCounter + 30);
399+
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
400+
401+
assertThat(GaugeCounter.count()).isEqualTo(priorGaugeCounter);
402+
}
403+
374404
@Test
375405
public void testUpdateAppStateHandlesMultipleAppStates() {
376406
PerfSession fakeSession = createTestSession(1);

0 commit comments

Comments
 (0)