Factories generate colliding URLs, failing tests at random #152
Labels
No labels
bug
devops
duplicate
enhancement
good first issue
layout
next major release
next minor release
question
research
testing
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lvl0/fedi-feed-router#152
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Several factories generate values with bare faker calls against columns that
carry unique constraints. Faker draws from a small pool, so duplicates occur at
random and fail whichever test happens to hit one.
FeedFactoryurl=>faker->url()unique('url')onfeedsPlatformInstanceFactoryurl=>faker->url()unique(['platform', 'url'])PlatformInstanceFactorylemmy()state urlPlatformAccountFactoryusername=>faker->userName()unique(['username', 'platform', 'is_active'])PlatformInstanceFactoryis the worst of these because every row it creates hasplatform => 'lemmy', so the composite constraint is effectively a constrainton
urlalone.Observed
Two separate failures, hours apart, from the same cause:
Why one collision can fail the whole suite
Under
RefreshDatabase, a test that dies mid-transaction leaves the connectionin a state where the next test cannot open a clean one:
Every subsequent test then fails during setup rather than on its own logic. One
CI run produced 809 errors from a single root collision. The error count is
not a measure of how much is broken.
Fix, and the complication
$this->faker->unique()on the four fields above resolves the collisions.Applying it is not sufficient on its own. With
unique()onPlatformInstanceFactory, these tests inPublishNextArticleJobTeststartfailing:
test_handle_skips_publishing_when_daily_cap_reachedtest_handle_publishes_when_below_daily_captest_handle_publishes_when_daily_cap_is_zeroThey call
ArticlePublication::factory()->count(50)->create(...)and thenassert against a daily publish cap. Today the colliding URLs mean those 50
publications resolve to far fewer distinct instances and channels than 50, and
the assertions depend on that reduced number. Making instances unique changes
the count and the expectations no longer hold.
So those tests currently pass because of a factory bug, not in spite of it.
Their setup needs to state explicitly how many publications should count toward
the cap, rather than inheriting whatever number collisions happen to produce.
Acceptance criteria
publications rather than relying on factory collisions
to produce
Notes
The repository has fixed this class of problem before:
Fix flaky test from duplicate Article factory URLsandFix flaky boundary test with freezeTime.Worth checking whether other factories have the same shape while this is open.