Fix MetricsPingSchedulerTest failing between midnight and 4am - #3611
Open
rvandermeulen wants to merge 1 commit into
Open
Fix MetricsPingSchedulerTest failing between midnight and 4am#3611rvandermeulen wants to merge 1 commit into
rvandermeulen wants to merge 1 commit into
Conversation
The scheduler reads "now" from Calendar.getInstance(), which Robolectric cannot shadow, while DateUtils.isToday() does see the simulated clock. Tests that set a fake time got a mix of the two, so startup collection only happened when the real local hour was past DUE_HOUR_OF_THE_DAY (4). Add a test-only clock override so the scheduler sees the simulated time.
Collaborator
Author
|
For the record, this has been annoying me for AGES. |
rvandermeulen
enabled auto-merge (rebase)
August 27, 2026 04:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MetricsPingSchedulerreads "now" fromCalendar.getInstance(), which Robolectric cannot shadow, whileDateUtils.isToday()does see the clock set bySystemClock.setCurrentTimeMillis(). Tests that install a fake time therefore got a mix of the simulated and real clocks.The visible effect is in
schedule(): startup collection only happens whenisAfterDueTime(now)is true, andnowwas the real time. Between midnight andDUE_HOUR_OF_THE_DAY(4am) local, the ping was scheduled for later in the day instead of collected immediately, so the mock web server never received it,takeRequesttimed out after 20s and!!threw an NPE.This affects
Data recorded before Glean inits must not get into overdue pingsandGlean must preserve lifetime application metrics across runs. It looks like a flake but is deterministic — it depends only on the local hour the suite runs at, which is a ~4h window per day for a UTC CI.getCalendarInstance()already existed as a seam, but the instance Glean builds instartMetricsPingScheduler()is not reachable from tests, so this adds a test-onlyclockOverridethat it consults. It is null in production, so there is no behavior change outside tests.GleanTestRulesets it alongside theSystemClockcall it already makes and clears it infinished().Verified by running the full
:glean:testDebugUnitTestsuite plusdetektandktlintat 00:24 and 00:28 local — inside the window where these tests failed at 00:02.