Skip to content

Commit

Permalink
Change from fixed rate to fixed delay (#332)
Browse files Browse the repository at this point in the history
* change from fixed rate to fixed delay

* disable AGP version check linter

* spotless
  • Loading branch information
breedx-splk committed May 2, 2024
1 parent 66de8ae commit 29aa5cd
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
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

0 comments on commit 29aa5cd

Please sign in to comment.