Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from fixed rate to fixed delay #332

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ android {
// A newer version of androidx.appcompat:appcompat than 1.3.1 is available: 1.4.1 [GradleDependency]
// we rely on dependabot for dependency updates
disable.add("GradleDependency")
disable.add("AndroidGradlePluginVersion")
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class AnrDetectorToggler implements ApplicationStateListener {
@Override
public void onApplicationForegrounded() {
if (future == null) {
future = anrScheduler.scheduleAtFixedRate(anrWatcher, 1, 1, TimeUnit.SECONDS);
future = anrScheduler.scheduleWithFixedDelay(anrWatcher, 1, 1, TimeUnit.SECONDS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void shouldInstallInstrumentation() {

// verify that the ANR scheduler was started
verify(scheduler)
.scheduleAtFixedRate(isA(AnrWatcher.class), eq(1L), eq(1L), eq(TimeUnit.SECONDS));
.scheduleWithFixedDelay(
isA(AnrWatcher.class), eq(1L), eq(1L), eq(TimeUnit.SECONDS));
// verify that an application listener was installed
verify(instrumentedApplication)
.registerApplicationStateListener(isA(AnrDetectorToggler.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class AnrDetectorTogglerTest {

@Test
void testOnApplicationForegrounded() {
doReturn(future).when(scheduler).scheduleAtFixedRate(anrWatcher, 1, 1, TimeUnit.SECONDS);
doReturn(future).when(scheduler).scheduleWithFixedDelay(anrWatcher, 1, 1, TimeUnit.SECONDS);

underTest.onApplicationForegrounded();
underTest.onApplicationForegrounded();
underTest.onApplicationForegrounded();

verify(scheduler, times(1)).scheduleAtFixedRate(anrWatcher, 1, 1, TimeUnit.SECONDS);
verify(scheduler, times(1)).scheduleWithFixedDelay(anrWatcher, 1, 1, TimeUnit.SECONDS);
}

@Test
void testOnApplicationBackgrounded() {
doReturn(future).when(scheduler).scheduleAtFixedRate(anrWatcher, 1, 1, TimeUnit.SECONDS);
doReturn(future).when(scheduler).scheduleWithFixedDelay(anrWatcher, 1, 1, TimeUnit.SECONDS);

underTest.onApplicationForegrounded();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static Looper startFrameMetricsLoop() {
// the returned future is very unlikely to fail
@SuppressWarnings("FutureReturnValueIgnored")
void start() {
executorService.scheduleAtFixedRate(
executorService.scheduleWithFixedDelay(
this::reportSlowRenders,
pollInterval.toMillis(),
pollInterval.toMillis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void start() {
return null;
})
.when(exec)
.scheduleAtFixedRate(any(), eq(1001L), eq(1001L), eq(TimeUnit.MILLISECONDS));
.scheduleWithFixedDelay(any(), eq(1001L), eq(1001L), eq(TimeUnit.MILLISECONDS));

SlowRenderListener testInstance =
new SlowRenderListener(tracer, exec, frameMetricsHandler, Duration.ofMillis(1001));
Expand Down