Fix a Flaky Test for Due Date Reminder Windows
Last updated: November 29, 2026
Quick Overview
A test for the 'due within 24 hours' reminder job passes locally but fails intermittently in CI. Explain the likely causes and refactor the code and test so the result is deterministic.
Asana
November 29, 20260
0
0 solved
A test for the 'due within 24 hours' reminder job passes locally but fails intermittently in CI. Explain the likely causes and refactor the code and test so the result is deterministic.
Asana engineers own their tests, and a flaky suite slows every team that ships to the same monolith. The interviewer wants to see a systematic debugging approach (reproduce, isolate the nondeterministic input) and a fix that removes hidden dependencies on wall-clock time rather than a retry decorator.
What the Interviewer Expects
- Identifies wall-clock time as the hidden input and explains why boundaries flip between runs
- Introduces an injectable clock instead of patching globals
- Defines the window boundary precisely (half-open interval)
- Uses timezone-aware UTC datetimes and mentions DST
- Adds explicit boundary tests
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- What other common sources of flakiness would you check for?
- How would you detect flaky tests automatically across the CI fleet?
- When, if ever, is retrying a flaky test acceptable?
- How would you test the job that sends the reminders, not just the selection logic?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
The job selects tasks due in the next 24 hours. The original code calls datetime.now() inside the function while the test builds fixtures with its own now() a few milliseconds earlier, and uses na...
High-Level Design
Make time an explicit dependency: the service takes a clock object. Production passes SystemClock; tests pass a FakeClock they can advance. Store and compare only UTC-aware datetimes. Specify th...