Skip to content

Commit c01019d

Browse files
committed
Update test and add a TODO
1 parent 9385461 commit c01019d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/session/gauges/GaugeManager.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ public void stopCollectingGauges() {
221221

222222
// This is needed, otherwise the Runnable might use a stale value.
223223

224-
// AQS is guaranteed to be available when stopping gauge collection.
225-
final String sessionIdForScheduledTask = session.aqsSessionId();
226224
final ApplicationProcessState applicationProcessStateForScheduledTask = applicationProcessState;
227225

228226
cpuGaugeCollector.get().stopCollecting();
@@ -232,6 +230,14 @@ public void stopCollectingGauges() {
232230
gaugeManagerDataCollectionJob.cancel(false);
233231
}
234232

233+
234+
final String sessionIdForScheduledTask = session.aqsSessionId();
235+
this.session = null;
236+
if (sessionIdForScheduledTask.equals(Constants.UNDEFINED_AQS_ID)) {
237+
// TODO(b/394127311): Use DebugEnforcementCheck.
238+
return;
239+
}
240+
235241
// Flush any data that was collected for this session one last time.
236242
@SuppressWarnings("FutureReturnValueIgnored")
237243
ScheduledFuture<?> unusedFuture =
@@ -244,7 +250,6 @@ public void stopCollectingGauges() {
244250
TIME_TO_WAIT_BEFORE_FLUSHING_GAUGES_QUEUE_MS,
245251
TimeUnit.MILLISECONDS);
246252

247-
this.session = null;
248253
}
249254

250255
/**
@@ -270,7 +275,6 @@ private void syncFlush(String sessionId, ApplicationProcessState appState) {
270275

271276
// Adding Session ID info.
272277
gaugeMetricBuilder.setSessionId(sessionId);
273-
274278
transportManager.log(gaugeMetricBuilder.build(), appState);
275279
}
276280

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,19 @@ public void testGaugeManagerDoesNotClearTheQueueUnlessUpdated() {
451451
assertThat(fakeCpuGaugeCollector.cpuMetricReadings).isNotEmpty();
452452
assertThat(fakeMemoryGaugeCollector.memoryMetricReadings).isNotEmpty();
453453

454+
455+
fakeSession.setAQSId(new SessionSubscriber.SessionDetails("aqsSessionId"));
454456
testGaugeManager.updateGaugeCollection(ApplicationProcessState.FOREGROUND);
455457

456458
fakeScheduledExecutorService.simulateSleepExecutingAtMostOneTask();
457459
assertThat(fakeCpuGaugeCollector.cpuMetricReadings).isEmpty();
458460
assertThat(fakeMemoryGaugeCollector.memoryMetricReadings).isEmpty();
461+
462+
assertThat(fakeScheduledExecutorService.isEmpty()).isFalse();
459463
}
460464

465+
466+
461467
@Test
462468
public void testLogGaugeMetadataSendDataToTransport() {
463469
when(fakeGaugeMetadataManager.getDeviceRamSizeKb()).thenReturn(2000);

0 commit comments

Comments
 (0)