Fix flaky tests caused by colliding factory slugs - #357
Merged
Merged
Conversation
Factories generated slugs with faker->word, which picks from a small lorem word list. When two records in one test got the same slug, lookups by slug could resolve the wrong record (e.g. ViewItemTest redirecting to another item's project page and returning 302 instead of 200).
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.
Problem
ViewItemTest > A user with admin access can render a private item page that has no associated projectfailed now and then in CI with a 302 instead of 200.The factories for Item, Project, Board and Changelog generated slugs with
$this->faker->word, which picks from a list of about 180 lorem words.ViewItemTest'sbeforeEachalready creates an item that belongs to a project. When the test's own item got the same slug,ItemController::show(where('slug', ...)->firstOrFail()) resolved the project item and redirected to its project page.Reproduced locally by running the test in a loop:
Fix
Use
$this->faker->unique()->slug()for the slug in all four factories.Verification
ViewItemTestwith 0 failures