Repository navigation
Description
Symptom
tests/fl/wdt/watchdog.cpp fails intermittently on CI, macOS runners so far:
../../tests/fl/wdt/watchdog.cpp:172: !(fired.load())
../../tests/fl/wdt/watchdog.cpp:173: 1 == 0
[FastLED.watchdog] WARN: nested FL_WATCHDOG_AUTO() detected — only one scoped guard should be alive at a time
[doctest] test cases: 26 | 25 passed | 1 failed
Seen on job 97100960253 (PR #3976, a Python/docs-only change that cannot touch
this code). Re-running the same job cleared it — the failure did not reproduce.
Why it is flaky
The test ("watchdog does not fire when fed") arms a 200 ms watchdog and
feeds it from a loop that sleeps 50 ms per iteration:
dog.begin(200);
for (int i = 0; i < 10; ++i) {
fl::this_thread::sleep_for(fl::chrono::milliseconds(50)); // ok sleep for
dog.feed();
}
dog.disable();
FL_CHECK_FALSE(fired.load());The margin between feed interval and timeout is 4×, but sleep_for only
guarantees a lower bound. On a loaded runner a single 50 ms sleep overshooting
to >200 ms — entirely ordinary under CPU contention on shared CI — means the
watchdog fires exactly as designed and the assertion fails. The test asserts a
real-time guarantee the host cannot make.
The stub's 10 ms tick granularity narrows the effective margin further.
Note on the sibling test
The test above it has the same shape in the other direction — dog.begin(50)
then a single 300 ms sleep asserting fired is set. That one is safe: a
sleep can only overshoot, which only makes firing more certain. The asymmetry is
worth preserving in any fix — the failure mode is one-directional.
Suggested fix
Options, roughly in order of preference:
- Widen the margin substantially (e.g.
begin(2000)with 50 ms feeds).
Cheapest, keeps the test's intent, makes overshoot implausible rather than
merely unlikely. - Drive the clock deterministically — if the stub's timer source can be
injected or advanced manually, the test stops depending on wall time at all.
Correct fix, more work. - Assert on feed bookkeeping rather than on not-firing, if the watchdog
exposes a feed count or last-fed timestamp.
Option 1 alone would likely take this from occasionally-red to effectively
never, without restructuring anything.
Impact
Low severity, real cost: an unrelated PR shows a red test / build that has
nothing to do with its diff, which trains reviewers to ignore that signal.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
test(wdt): make micros64() the stub's single clock root and mock it
test(wdt): make feed timing deterministic (#3978) (#4082)