fix(testutil): derive a per-workspace database for non-.test binaries - #983
Open
AmirF194 wants to merge 2 commits into
Open
fix(testutil): derive a per-workspace database for non-.test binaries#983AmirF194 wants to merge 2 commits into
AmirF194 wants to merge 2 commits into
Conversation
derivedDBSuffix() only derived the per-workspace, per-package database suffix when os.Args[0] ended in ".test", so cmd/e2a-contract-server, the one non-test binary sharing this harness, fell back to the base URL verbatim. Two contract-server instances from different checkouts (two agents, two worktrees) landed on the same e2a_test database and truncated each other's rows on Close. The suffix is now keyed on the running binary's own name regardless of a ".test" suffix, so a compiled binary derives one too. testutil is imported by exactly one other non-test file, cmd/e2a-contract-server; every other consumer is already a `go test` binary and derives the same suffix it did before. Fixes tokencanopy#827
Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
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.
Summary
derivedDBSuffix()(internal/testutil/db.go) only derived the per-workspace,per-package test database name when
os.Args[0]ended in.test. The onenon-test binary sharing this harness,
cmd/e2a-contract-server, fell back tothe base URL verbatim, so two instances started from different checkouts (two
agents, two worktrees) landed on the same
e2a_testdatabase and truncatedeach other's rows on
Close, exactly as #827 describes.The suffix is now keyed on the running binary's own name regardless of a
.testsuffix, socmd/e2a-contract-serverderives its own per-workspacedatabase the same way a
go testbinary already does.testutilis importedby exactly one other non-test file,
cmd/e2a-contract-server/main.go; everyother consumer is a
go testbinary and derives the same suffix it didbefore.
This PR doesn't touch the API or any client surface, so I've dropped the
client surface checklist.
Test plan
TestTestDBURLDerivesForNonTestBinaries: fails onmain(derived name is the bare base,e2a_test) and passes on thisbranch (
*_ws<hash>_pkg_e2a_contract_server), both run against a realPostgres 16 container.
cmd/e2a-contract-serverbinary and ran two instances fromtwo different checkout paths against the same Postgres server: they landed
on two distinct
e2a_test_ws*_pkg_e2a_contract_serverdatabases.internal/testutilsuite green against Postgres 16(
go test ./internal/testutil/... -v).go test ./...,gofmt/make fmt-check, andgo vetall clean.