@@ -353,7 +353,7 @@ public void testGaugeCounterStartsAJobToConsumeTheGeneratedMetrics() {
353
353
assertThat (fakeScheduledExecutorService .isEmpty ()).isTrue ();
354
354
355
355
GaugeMetric recordedGaugeMetric =
356
- getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND , 1 );
356
+ getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
357
357
358
358
// It flushes all the original metrics in the ConcurrentLinkedQueues, but not the new ones
359
359
// added after the task completed.
@@ -389,8 +389,12 @@ public void testUpdateAppStateFlushesMetricsInTheCurrentAppState() {
389
389
.isEqualTo (TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS );
390
390
391
391
fakeScheduledExecutorService .simulateSleepExecutingAtMostOneTask ();
392
+
393
+ // Generate additional metrics that shouldn't be included in the flush.
394
+ generateMetricsAndIncrementCounter (5 );
395
+
392
396
GaugeMetric recordedGaugeMetric =
393
- getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND , 1 );
397
+ getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
394
398
395
399
// It flushes all metrics in the ConcurrentLinkedQueues.
396
400
int recordedGaugeMetricsCount =
@@ -440,7 +444,7 @@ public void testStopCollectingGaugesCreatesOneLastJobToConsumeAnyPendingMetrics(
440
444
441
445
fakeScheduledExecutorService .simulateSleepExecutingAtMostOneTask ();
442
446
GaugeMetric recordedGaugeMetric =
443
- getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND , 1 );
447
+ getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
444
448
assertThatCpuGaugeMetricWasSentToTransport (
445
449
testSessionId (1 ), recordedGaugeMetric , fakeCpuMetricReading );
446
450
assertThatMemoryGaugeMetricWasSentToTransport (
@@ -456,7 +460,7 @@ public void testLogGaugeMetadataSendDataToTransport() {
456
460
testGaugeManager .logGaugeMetadata (testSessionId (1 ), ApplicationProcessState .FOREGROUND );
457
461
458
462
GaugeMetric recordedGaugeMetric =
459
- getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND , 1 );
463
+ getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
460
464
GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric .getGaugeMetadata ();
461
465
462
466
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (1 ));
@@ -507,7 +511,7 @@ public void testLogGaugeMetadataLogsAfterApplicationContextIsSet() {
507
511
.isTrue ();
508
512
509
513
GaugeMetric recordedGaugeMetric =
510
- getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND , 1 );
514
+ getLastRecordedGaugeMetric (ApplicationProcessState .FOREGROUND );
511
515
GaugeMetadata recordedGaugeMetadata = recordedGaugeMetric .getGaugeMetadata ();
512
516
513
517
assertThat (recordedGaugeMetric .getSessionId ()).isEqualTo (testSessionId (1 ));
@@ -563,16 +567,15 @@ private AndroidMemoryReading createFakeAndroidMetricReading(int currentUsedAppJa
563
567
* Gets the last recorded GaugeMetric, and verifies that they were logged for the right {@link
564
568
* ApplicationProcessState}.
565
569
*
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.
569
572
* @return The last logged {@link GaugeMetric}.
570
573
*/
571
574
private GaugeMetric getLastRecordedGaugeMetric (
572
- ApplicationProcessState applicationProcessState , int timesLogged ) {
575
+ ApplicationProcessState expectedApplicationProcessState ) {
573
576
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 ));
576
579
reset (mockTransportManager );
577
580
// Required after resetting the mock. By default we assume that Transport is initialized.
578
581
when (mockTransportManager .isInitialized ()).thenReturn (true );
0 commit comments