@@ -252,6 +252,7 @@ public void testStartFromBackground() {
252
252
++currentTime ;
253
253
trace .onActivityResumed (activity1 );
254
254
Assert .assertNull (trace .getOnResumeTime ());
255
+ fakeExecutorService .runAll ();
255
256
// There should be no trace sent.
256
257
verify (transportManager , times (0 ))
257
258
.log (
@@ -278,10 +279,37 @@ public void testStartFromBackground_invertedOrder() {
278
279
++currentTime ;
279
280
trace .onActivityResumed (activity1 );
280
281
Assert .assertNotNull (trace .getOnResumeTime ());
282
+ fakeExecutorService .runAll ();
283
+ // There should be no trace sent.
284
+ verify (transportManager , times (1 ))
285
+ .log (
286
+ traceArgumentCaptor .capture (),
287
+ ArgumentMatchers .nullable (ApplicationProcessState .class ));
288
+ }
289
+
290
+ @ Test
291
+ public void testStartFromBackground_delayedInvertedOrder () {
292
+ FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService ();
293
+ Timer fakeTimer = spy (new Timer (currentTime ));
294
+ AppStartTrace trace =
295
+ new AppStartTrace (transportManager , clock , configResolver , fakeExecutorService );
296
+ trace .registerActivityLifecycleCallbacks (appContext );
297
+ trace .setIsStartFromBackground ();
298
+ trace .setMainThreadRunnableTime (fakeTimer );
299
+
300
+ when (fakeTimer .getDurationMicros ()).thenReturn (TimeUnit .MILLISECONDS .toMicros (100 ) + 1 );
301
+ trace .onActivityCreated (activity1 , bundle );
302
+ Assert .assertNull (trace .getOnCreateTime ());
303
+ ++currentTime ;
304
+ trace .onActivityStarted (activity1 );
305
+ Assert .assertNull (trace .getOnStartTime ());
306
+ ++currentTime ;
307
+ trace .onActivityResumed (activity1 );
308
+ Assert .assertNull (trace .getOnResumeTime ());
281
309
// There should be a trace sent since the delay between the main thread and onActivityCreated
282
310
// is limited.
283
311
fakeExecutorService .runAll ();
284
- verify (transportManager , times (1 ))
312
+ verify (transportManager , times (0 ))
285
313
.log (
286
314
traceArgumentCaptor .capture (),
287
315
ArgumentMatchers .nullable (ApplicationProcessState .class ));
0 commit comments