Adjusted randomness for factories to fix rare failure collisions - #951
Conversation
🤖 Augment PR SummarySummary: This PR hardens Factory Boy test data generation to be deterministic and avoid rare identity collisions that intermittently fail CI. Changes:
Technical Notes: The overall goal is to reduce flaky CI failures caused by randomness and unique-constraint collisions in factories. 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Pull request overview
This PR hardens Ghostwriter’s Django test factories and a few reporting tests to avoid rare, random collisions and improve determinism in test fixtures (referenced CI flake link in the PR description).
Changes:
- Made several factory identity fields deterministic/unique (e.g., usernames, client names, domain names, IPs) and reduced random boolean/date/time generation.
- Updated reporting preview view tests to use explicit usernames and added a few assertions to fail fast on unexpected response codes/roles.
- Added targeted tests to ensure the “mock project” fixture contains deliberate data variants and that factory identity collisions fail loudly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ghostwriter/reporting/tests/test_views.py | Uses explicit usernames for preview tests and adds extra assertions to reduce flakiness. |
| ghostwriter/reporting/tests/test_serializers.py | Adds assertions verifying GenerateMockProject() produces deliberate variants (severities, assignees, states). |
| ghostwriter/home/tests/test_factories.py | New tests to validate factory uniqueness and role/privilege behavior. |
| ghostwriter/factories.py | Core changes: deterministic sequences/defaults to reduce collisions; deterministic distribution in GenerateMockProject(). |
Comments suppressed due to low confidence (1)
ghostwriter/factories.py:1200
- Same issue as above: without passing
project=project, the connection will be linked to a newly created Project from the factory default instead of theprojectcreated inGenerateMockProject().
DomainServerConnectionFactory(
domain=domain,
transient_server=cloud[index % len(cloud)],
static_server=None,
)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #951 +/- ##
==========================================
+ Coverage 92.17% 92.20% +0.02%
==========================================
Files 443 444 +1
Lines 33872 33957 +85
==========================================
+ Hits 31223 31309 +86
+ Misses 2649 2648 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Hardening pass on test cases to fix random, rare failures like https://github.com/GhostManager/Ghostwriter/actions/runs/30086305686/job/89459171980.