Skip to content

fix(tests): give mock records unique IDs - #451

Merged
M0Rf30 merged 1 commit into
openartifact:mainfrom
orcamedia:fix/tests-unique-mock-ids
Nov 9, 2026
Merged

M0Rf30 merged 1 commit into
openartifact:mainfrom
orcamedia:fix/tests-unique-mock-ids

Conversation

@orcamedia

Copy link
Copy Markdown
Contributor

Two tests in tests/ fail every time on an Apple Silicon Mac:

go test -short -count=20 -run 'TestRepositoriesHandler_HandleList_(Pagination|FormatFilter)$' ./tests/
--- FAIL: TestRepositoriesHandler_HandleList_Pagination
    repositories_handler_test.go:114: expected total=3, got 2
--- FAIL: TestRepositoriesHandler_HandleList_FormatFilter
    repositories_handler_test.go:154: expected 2 rpm repos, got 1

The mock database names new records fmt.Sprintf("mock-%d", time.Now().UnixNano()). On macOS the wall clock advances once per microsecond, so repositories seeded back to back get the same ID and overwrite each other in the mock's map. On Linux the clock is fine-grained enough that it rarely shows, which is why CI is green.

This adds mockID, which appends a package-wide atomic counter to the timestamp, and uses it for all eight generated IDs in tests/rpm_db_wiring_test.go (seven mock- and one blob-). The timestamp stays, so the IDs keep their shape and can't collide with hard-coded ones like blob-1. Test-only change. The two tests above are the regression tests: they fail without this on macOS.

Checked on macOS: the two tests pass 50 of 50 runs, make check passes, and go test -short ./... passes with and without -tags noai,nomcp (race on for the default build).

Found while preparing the slim-tag CI follow-up from #448, which comes next as its own PR.

🤖 Generated with Claude Code

The mock database and blob store named new records
fmt.Sprintf("mock-%d", time.Now().UnixNano()). On macOS the wall clock
advances once per microsecond, so records created back to back got the
same ID and overwrote each other in the mock's maps.
TestRepositoriesHandler_HandleList_Pagination and _FormatFilter failed
20 out of 20 runs on an Apple Silicon Mac ("expected total=3, got 2").

Add mockID, which appends a package-wide counter to the timestamp, and
use it for all eight generated IDs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@M0Rf30
M0Rf30 merged commit be4dff6 into openartifact:main Nov 9, 2026
23 checks passed
@orcamedia
orcamedia deleted the fix/tests-unique-mock-ids branch November 9, 2026 18:26
@M0Rf30 M0Rf30 mentioned this pull request Nov 9, 2026
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.

2 participants