Deflake ScheduleGeneratorTest — unseeded random dish selection #63

Open
opened 2026-08-21 00:08:33 +02:00 by myrmidex · 0 comments
Owner

Problem

tests/Unit/Schedule/ScheduleGeneratorTest.php::test_it_takes_minimum_recurrences_into_account fails intermittently:

Recurring dish was not scheduled often enough to verify spacing
Failed asserting that 1 is greater than 1.

at tests/Unit/Schedule/ScheduleGeneratorTest.php:138.

Observed 5 green / 1 red across six runs on an identical tree (2026-08-20, during the #55 flow). It is not a regression — it reproduces without any code change.

Root cause

Schedule generation picks dishes with unseeded ->random():

  • RegenerateScheduleForDateForUsersAction.php:33
  • RegenerateScheduleDayForUserAction.php:28,45
  • DraftScheduleForDateAction.php:22
  • GenerateScheduleForMonthAction.php:90

The test fixture creates two dishes — one plain, one with a MinimumRecurrence. The test then asserts the recurring dish landed on more than one date so it can measure spacing between occurrences. With two candidates and no seeded RNG, whether the recurring dish is chosen twice is effectively a coin flip, so $recurringDates->count() is sometimes exactly 1 and the assertion trips.

The assertion is guarding against this case correctly — it is guarding by failing, rather than the outcome being made deterministic.

Note

c3a5532 60 - Make schedule test assertion counts deterministic already addressed this same class of flakiness in this same file, so this is a second pass at a known problem area rather than a new discovery.

Suggested approaches

Not prescriptive — whichever fits the subsystem best:

  • Seed the RNG for the test, so selection is reproducible
  • Enlarge the fixture so the recurring dish is near-certain to be scheduled more than once
  • Make the assertion independent of how many times the dish happened to be picked (assert spacing only across the occurrences that exist, and skip when there are fewer than two)
  • Inject the dish-picking strategy so tests can supply a deterministic one

Acceptance

  • Root cause addressed, not just the assertion loosened
  • Test passes reliably across repeated runs (e.g. 20 consecutive)
  • No change to production scheduling behaviour
## Problem `tests/Unit/Schedule/ScheduleGeneratorTest.php::test_it_takes_minimum_recurrences_into_account` fails intermittently: ``` Recurring dish was not scheduled often enough to verify spacing Failed asserting that 1 is greater than 1. ``` at `tests/Unit/Schedule/ScheduleGeneratorTest.php:138`. Observed **5 green / 1 red across six runs on an identical tree** (2026-08-20, during the #55 flow). It is not a regression — it reproduces without any code change. ## Root cause Schedule generation picks dishes with unseeded `->random()`: - `RegenerateScheduleForDateForUsersAction.php:33` - `RegenerateScheduleDayForUserAction.php:28,45` - `DraftScheduleForDateAction.php:22` - `GenerateScheduleForMonthAction.php:90` The test fixture creates **two** dishes — one plain, one with a `MinimumRecurrence`. The test then asserts the recurring dish landed on more than one date so it can measure spacing between occurrences. With two candidates and no seeded RNG, whether the recurring dish is chosen twice is effectively a coin flip, so `$recurringDates->count()` is sometimes exactly 1 and the assertion trips. The assertion is guarding against this case correctly — it is guarding by failing, rather than the outcome being made deterministic. ## Note `c3a5532 60 - Make schedule test assertion counts deterministic` already addressed this same class of flakiness in this same file, so this is a second pass at a known problem area rather than a new discovery. ## Suggested approaches Not prescriptive — whichever fits the subsystem best: - Seed the RNG for the test, so selection is reproducible - Enlarge the fixture so the recurring dish is near-certain to be scheduled more than once - Make the assertion independent of how many times the dish happened to be picked (assert spacing only across the occurrences that exist, and skip when there are fewer than two) - Inject the dish-picking strategy so tests can supply a deterministic one ## Acceptance - [ ] Root cause addressed, not just the assertion loosened - [ ] Test passes reliably across repeated runs (e.g. 20 consecutive) - [ ] No change to production scheduling behaviour
myrmidex added this to the v0.9.0 milestone 2026-08-21 00:08:33 +02:00
myrmidex added the
bug
testing
labels 2026-08-21 00:08:33 +02:00
myrmidex self-assigned this 2026-08-21 17:12:59 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lvl0/dishplanner#63
No description provided.