Skip to content

Commit 8e74729

Browse files
committed
Update threshold to 50ms and update tests.
1 parent a1fe411 commit 8e74729

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public class AppStartTrace implements ActivityLifecycleCallbacks, LifecycleObser
7777

7878
// If the `mainThreadRunnableTime` was set within this duration, the assumption
7979
// is that it was called immediately before `onActivityCreated` in foreground starts on API 34+.
80-
private static final long MAX_BACKGROUND_RUNNABLE_DELAY = TimeUnit.MILLISECONDS.toMicros(100);
80+
private static final long MAX_BACKGROUND_RUNNABLE_DELAY = TimeUnit.MILLISECONDS.toMicros(50);
8181

8282
// Core pool size 0 allows threads to shut down if they're idle
8383
private static final int CORE_POOL_SIZE = 0;

firebase-perf/src/test/java/com/google/firebase/perf/metrics/AppStartTraceTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,16 @@ public void testDelayedAppStart() {
239239
}
240240

241241
@Test
242-
public void testStartFromBackground_within100ms() {
242+
public void testStartFromBackground_within50ms() {
243243
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
244244
Timer fakeTimer = spy(new Timer(currentTime));
245245
AppStartTrace trace =
246246
new AppStartTrace(transportManager, clock, configResolver, fakeExecutorService);
247247
trace.registerActivityLifecycleCallbacks(appContext);
248248
trace.setMainThreadRunnableTime(fakeTimer);
249249

250-
when(fakeTimer.getDurationMicros()).thenReturn(99L);
250+
// See AppStartTrace.MAX_BACKGROUND_RUNNABLE_DELAY.
251+
when(fakeTimer.getDurationMicros()).thenReturn(TimeUnit.MILLISECONDS.toMicros(50) - 1);
251252
trace.onActivityCreated(activity1, bundle);
252253
Assert.assertNotNull(trace.getOnCreateTime());
253254
++currentTime;
@@ -266,15 +267,16 @@ public void testStartFromBackground_within100ms() {
266267
}
267268

268269
@Test
269-
public void testStartFromBackground_moreThan100ms() {
270+
public void testStartFromBackground_moreThan50ms() {
270271
FakeScheduledExecutorService fakeExecutorService = new FakeScheduledExecutorService();
271272
Timer fakeTimer = spy(new Timer(currentTime));
272273
AppStartTrace trace =
273274
new AppStartTrace(transportManager, clock, configResolver, fakeExecutorService);
274275
trace.registerActivityLifecycleCallbacks(appContext);
275276
trace.setMainThreadRunnableTime(fakeTimer);
276277

277-
when(fakeTimer.getDurationMicros()).thenReturn(TimeUnit.MILLISECONDS.toMicros(100) + 1);
278+
// See AppStartTrace.MAX_BACKGROUND_RUNNABLE_DELAY.
279+
when(fakeTimer.getDurationMicros()).thenReturn(TimeUnit.MILLISECONDS.toMicros(50) + 1);
278280
trace.onActivityCreated(activity1, bundle);
279281
Assert.assertNull(trace.getOnCreateTime());
280282
++currentTime;

0 commit comments

Comments
 (0)