File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
main/java/com/google/firebase/perf/application
test/java/com/google/firebase/perf/application Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ public Optional<PerfFrameMetrics> stop() {
89
89
return Optional .absent ();
90
90
}
91
91
if (!fragmentSnapshotMap .isEmpty ()) {
92
- // Instrumentation will be stopped and return activity data. Dangling fragments will fail.
92
+ // Instrumentation stops and still return activity data, but invalidate all dangling fragments
93
93
logger .debug (
94
94
"Sub-recordings are still ongoing! Sub-recordings should be stopped first before stopping Activity screen trace." );
95
95
fragmentSnapshotMap .clear ();
Original file line number Diff line number Diff line change @@ -199,6 +199,27 @@ public void startAndStopSubTrace_whenTwoSubTracesOverlap_returnsCorrectResults()
199
199
assertThat (subTrace2 .get ().getFrozenFrames ()).isEqualTo (5 - 2 );
200
200
}
201
201
202
+ /**
203
+ * This case happens when AppStateMonitor calls stop() before all Fragment traces are stopped by
204
+ * stopFragment(fragment), leaving some dangling fragment traces that are invalid. Even if
205
+ * activity recording starts again later, then stopFragment(fragment) is called, it should not
206
+ * return a result which is incorrect.
207
+ */
208
+ @ Test
209
+ public void
210
+ startAndStopSubTrace_notContainedWithinActivityRecordingStartAndStop_returnsEmptyResult () {
211
+ Fragment fragment = new Fragment ();
212
+ recorder .start ();
213
+ stubFrameMetricsAggregatorData (fma , frameTimesDefault );
214
+ recorder .startFragment (fragment );
215
+ stubFrameMetricsAggregatorData (fma , frameTimes1 );
216
+ recorder .stop ();
217
+ recorder .start ();
218
+ stubFrameMetricsAggregatorData (fma , frameTimes2 );
219
+ Optional <PerfFrameMetrics > result = recorder .stopFragment (fragment ); // invalid dangling trace
220
+ assertThat (result .isAvailable ()).isFalse ();
221
+ }
222
+
202
223
private static Activity createFakeActivity (boolean isHardwareAccelerated ) {
203
224
ActivityController <Activity > fakeActivityController = Robolectric .buildActivity (Activity .class );
204
225
You can’t perform that action at this time.
0 commit comments