Skip to content

Commit 1898233

Browse files
committed
Update tests
1 parent c38a5ae commit 1898233

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
353353
assertThat(fakeScheduledExecutorService.isEmpty()).isTrue();
354354

355355
GaugeMetric recordedGaugeMetric =
356-
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
356+
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND);
357357

358358
// It flushes all the original metrics in the ConcurrentLinkedQueues, but not the new ones
359359
// added after the task completed.
@@ -389,8 +389,12 @@ public void testUpdateAppStateFlushesMetricsInTheCurrentAppState() {
389389
.isEqualTo(TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS);
390390

391391
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
392+
393+
// Generate additional metrics that shouldn't be included in the flush.
394+
generateMetricsAndIncrementCounter(5);
395+
392396
GaugeMetric recordedGaugeMetric =
393-
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
397+
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND);
394398

395399
// It flushes all metrics in the ConcurrentLinkedQueues.
396400
int recordedGaugeMetricsCount =
@@ -440,7 +444,7 @@ public void testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics(
440444

441445
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
442446
GaugeMetric recordedGaugeMetric =
443-
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
447+
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND);
444448
assertThatCpuGaugeMetricWasSentToTransport(
445449
testSessionId(1), recordedGaugeMetric, fakeCpuMetricReading);
446450
assertThatMemoryGaugeMetricWasSentToTransport(
@@ -456,7 +460,7 @@ public void testLogGaugeMetadataSendDataToTransport() {
456460
testGaugeManager.logGaugeMetadata(testSessionId(1), ApplicationProcessState.FOREGROUND);
457461

458462
GaugeMetric recordedGaugeMetric =
459-
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
463+
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND);
460464
GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
461465

462466
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
@@ -507,7 +511,7 @@ public void testLogGaugeMetadataLogsAfterApplicationContextIsSet() {
507511
.isTrue();
508512

509513
GaugeMetric recordedGaugeMetric =
510-
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND, 1);
514+
getLastRecordedGaugeMetric(ApplicationProcessState.FOREGROUND);
511515
GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric.getGaugeMetadata();
512516

513517
assertThat(recordedGaugeMetric.getSessionId()).isEqualTo(testSessionId(1));
@@ -563,16 +567,15 @@ private AndroidMemoryReading createFakeAndroidMetricReading(int currentUsedAppJa
563567
* Gets the last recorded GaugeMetric, and verifies that they were logged for the right {@link
564568
* ApplicationProcessState}.
565569
*
566-
* @param applicationProcessState The expected {@link ApplicationProcessState} that it was logged
567-
* to.
568-
* @param timesLogged Number of {@link GaugeMetric} that were expected to be logged to Transport.
570+
* @param expectedApplicationProcessState The expected {@link ApplicationProcessState} that it was logged
571+
* to.
569572
* @return The last logged {@link GaugeMetric}.
570573
*/
571574
private GaugeMetric getLastRecordedGaugeMetric(
572-
ApplicationProcessState applicationProcessState, int timesLogged) {
575+
ApplicationProcessState expectedApplicationProcessState) {
573576
ArgumentCaptor<GaugeMetric> argMetric = ArgumentCaptor.forClass(GaugeMetric.class);
574-
verify(mockTransportManager, times(timesLogged))
575-
.log(argMetric.capture(), eq(applicationProcessState));
577+
verify(mockTransportManager, times(1))
578+
.log(argMetric.capture(), eq(expectedApplicationProcessState));
576579
reset(mockTransportManager);
577580
// Required after resetting the mock. By default we assume that Transport is initialized.
578581
when(mockTransportManager.isInitialized()).thenReturn(true);

0 commit comments

Comments
 (0)