Skip to content

PR6a - fix(spec): make factory sequences unique per process - #8504

Open
LWS49 wants to merge 1 commit into
lws49/feat-marketplace-pr5b-miscfrom
lws49/feat-marketplace-pr6a-factories
Open

PR6a - fix(spec): make factory sequences unique per process#8504
LWS49 wants to merge 1 commit into
lws49/feat-marketplace-pr5b-miscfrom
lws49/feat-marketplace-pr6a-factories

Conversation

@LWS49

@LWS49 LWS49 commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Spec factories built a bare per-second timestamp into their sequences. Specs run with use_transactional_fixtures disabled, so two rspec processes that start within the same second generate identical values and trip unique constraints. Appending the pid makes the sequences unique regardless of when a process starts: two processes that share a database run on the same host, so their pids cannot collide while both are alive, and the timestamp keeps a recycled pid out of the same second while still making leaked rows traceable to a run.

This also moves the global userstamp setup into a before(:suite) hook and resolves the stamper by the seeded admin email instead of the lowest-id human. The stamper becomes the creator (and owner course_user) of courses built in specs, and mail-sending specs deliver to that owner, so it must own a valid email. Because the suite commits without cleanup, a spec that removes the seeded admin's email leaves it removed; the next process's db:seed then recreates the admin as a new user and the lowest-id human is permanently emailless. Setting the stamper at file-load time ran before db:seed and re-froze that stale user.

Regression prevention

Covers two sequences that carried a bare timestamp: instance hosts and user email. The values only ever need to be unique, never stable or predictable, so no spec depends on their format. Exercised by every parallel rspec run.

@LWS49
LWS49 force-pushed the lws49/feat-marketplace-pr6a-factories branch 2 times, most recently from 8e63f2b to bb91fa7 Compare July 24, 2026 04:34
@LWS49 LWS49 changed the title fix(spec): make factory sequences unique per process PR6a - fix(spec): make factory sequences unique per process Jul 24, 2026
Specs commit (use_transactional_fixtures is false), so a bare per-second
timestamp collides whenever two rspec processes start within the same second,
tripping unique constraints. Append the pid: two processes sharing a database
run on the same host, so their pids cannot collide, and the timestamp keeps a
recycled pid out of the same second.
@LWS49
LWS49 force-pushed the lws49/feat-marketplace-pr6a-factories branch from bb91fa7 to 433c1b3 Compare July 29, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant