@@ -252,6 +252,7 @@ public void testStartFromBackground() {
252252 ++currentTime ;
253253 trace .onActivityResumed (activity1 );
254254 Assert .assertNull (trace .getOnResumeTime ());
255+ fakeExecutorService .runAll ();
255256 // There should be no trace sent.
256257 verify (transportManager , times (0 ))
257258 .log (
@@ -278,10 +279,37 @@ public void testStartFromBackground_invertedOrder() {
278279 ++currentTime ;
279280 trace .onActivityResumed (activity1 );
280281 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 ());
281309 // There should be a trace sent since the delay between the main thread and onActivityCreated
282310 // is limited.
283311 fakeExecutorService .runAll ();
284- verify (transportManager , times (1 ))
312+ verify (transportManager , times (0 ))
285313 .log (
286314 traceArgumentCaptor .capture (),
287315 ArgumentMatchers .nullable (ApplicationProcessState .class ));
0 commit comments