You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3d1f55e
Browse filesBrowse the repository at this point in the historyBrowse files
ref(android): Measure ANR thresholds on the monotonic clock (JAVA-579) (#6041)
* test(time): Publish the TestMonotonicTicker tick to other threads
The ANR tests advance the ticker from the test thread while the watchdog
thread reads it, which without volatile is a data race that can leave the
watchdog looking at a stale tick forever.
* ref(android): Measure ANR thresholds on the monotonic clock (JAVA-579)
The watchdog took its readings from an ICurrentDateProvider lambda over
SystemClock.uptimeMillis(). The type named no clock, so a call site could
not tell what it was measuring, and the arithmetic -- now minus the last
tick, compared against a threshold -- was spelled out inline.
MonotonicClock and Deadline replace both: the clock is a named type, and
the watchdog asks the question it actually cares about, which is whether
the main thread has missed its window.
The clock counts deep sleep, which uptimeMillis() did not, so a suspend
between posting the ticker and checking it now looks like a missed
window. It cannot fabricate an ANR: the watchdog reports only once
ActivityManager confirms the process is NOT_RESPONDING, and on resume the
main thread runs the ticker that is already queued.
* ref(android): Measure ANR profiling on the monotonic clock (JAVA-579)
Same reasoning as the watchdog: the suspicion and ANR thresholds are now
read from a named clock rather than SystemClock, and injecting it lets the
tests drive it directly instead of going through Robolectric's shadow
clock.
Deep sleep cannot inflate the measurement here either, because the polling
thread parks itself while the app is backgrounded and resets the baseline
when it wakes.
* changelog
* ref(time): Supply the ANR ticker through MonotonicTickerProvider (JAVA-579)
Both ANR detectors resolved AndroidMonotonicTicker.getInstance() themselves,
so each call site named the concrete Android ticker and neither could be
pointed at another one. SentryAndroidOptions already knows which ticker the
platform wants, but it is final, so a test cannot override the getter.
Add a one-method MonotonicTickerProvider that SentryOptions implements.
ANRWatchDog gains a static factory that reads its timeout, debug behavior,
logger and ticker off options, replacing the telescoping convenience
constructor. AnrProfilingIntegration installs the ticker in register(),
which drops the two constructors it had grown and leaves the public no-arg
constructor and sentry-android-core.api unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* ref(android): Require an installed ticker for ANR profiling (JAVA-579)
Drop the JavaMonotonicTicker fallback. On Android nanoTime() stops while the
device is suspended, so a default that is never meant to be used would measure
main-thread stalls against the wrong clock if it ever were.
Start the test ticker at a non-zero origin. A fake that starts at zero makes a
reading taken against a different origin indistinguishable from a correct one,
which is the mistake this whole change exists to prevent.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* ref(android): Pass the ANR profiling ticker directly (JAVA-579)
MonotonicTickerProvider only existed so a test could hand
AnrProfilingIntegration a fake ticker. A package-private method taking
the ticker does the same without a new core interface or a change to
the SentryOptions supertype.
Also rename the ANRWatchDog test that claimed to cover a device suspend:
the Android ticker counts suspend, so the test only shows the threshold
is measured on the injected ticker rather than wall time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* ref(android): Read the ANR profiling ticker from options (JAVA-579)
Tests spy SentryAndroidOptions to supply a TestMonotonicTicker, so the
package-private installTicker seam is no longer needed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* ref(android): Drop the UnnecessaryLambda suppression in ANR profiling (JAVA-579)
Error Prone does not run on sentry-android-core, so the suppression had no effect. The lambda
field stays: removeCallbacks matches the posted Runnable by identity.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
0 commit comments