handlers/internal: fix db.DB pollution in registry and scheduler test helpers
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 9s
CI / Detect changes (pull_request) Successful in 20s
E2E API Smoke Test / detect-changes (pull_request) Successful in 21s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 21s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 19s
publish-runtime-autobump / bump-and-tag (pull_request) Has been skipped
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 13s
gate-check-v3 / gate-check (pull_request) Successful in 16s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 21s
Harness Replays / detect-changes (pull_request) Successful in 38s
qa-review / approved (pull_request) Failing after 10s
publish-runtime-autobump / pr-validate (pull_request) Successful in 37s
sop-checklist / na-declarations (pull_request) awaiting /sop-n/a declaration for: qa-review, security-review
security-review / approved (pull_request) Failing after 11s
sop-checklist / all-items-acked (pull_request) Successful in 10s
sop-tier-check / tier-check (pull_request) Successful in 9s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 4s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m10s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Failing after 1m20s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 1m31s
CI / Platform (Go) (pull_request) Failing after 3m7s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Failing after 3m0s
Harness Replays / Harness Replays (pull_request) Failing after 1m28s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2m54s
CI / Python Lint & Test (pull_request) Failing after 7m19s
CI / Canvas (Next.js) (pull_request) Failing after 11m7s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 11m42s
CI / all-required (pull_request) Failing after 4s

Five more test helpers have the same setupTestDB bug (save db.DB but
don't restore on teardown). go test -race runs tests in parallel; when
test A sets db.DB = mockA and test B sets db.DB = mockB, if A runs
first and cleanup closes mockA, B then runs with db.DB pointing at a
closed mock.

Fixed files:
- internal/registry/liveness_test.go    setupLivenessTestDB
- internal/registry/hibernation_test.go  setupHibernationMock
- internal/registry/access_test.go      setupMockDB
- internal/registry/healthsweep_test.go  setupTestDB
- internal/scheduler/scheduler_test.go   setupTestDB

All now follow: prevDB := db.DB; db.DB = mockDB;
t.Cleanup(func() { mockDB.Close(); db.DB = prevDB })

Total files fixed for mc#975: 8 files, ~20 test helper functions across
the workspace-server. Together with the CI fix to remove the
PHASE3_MASKED workaround, this should make CI/Platform (Go) stable.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · core-devops 2026-05-14 09:28:58 +00:00
parent cc987f8396
commit a9fb70a3be
5 changed files with 10 additions and 5 deletions

View File

@ -14,8 +14,9 @@ func setupMockDB(t *testing.T) sqlmock.Sqlmock {
if err != nil {
t.Fatalf("sqlmock: %v", err)
}
prevDB := db.DB
db.DB = mockDB
t.Cleanup(func() { mockDB.Close() })
t.Cleanup(func() { mockDB.Close(); db.DB = prevDB })
return mock
}

View File

@ -31,8 +31,9 @@ func setupTestDB(t *testing.T) sqlmock.Sqlmock {
if err != nil {
t.Fatalf("failed to create sqlmock: %v", err)
}
prevDB := db.DB
db.DB = mockDB
t.Cleanup(func() { mockDB.Close() })
t.Cleanup(func() { mockDB.Close(); db.DB = prevDB })
return mock
}

View File

@ -17,8 +17,9 @@ func setupHibernationMock(t *testing.T) sqlmock.Sqlmock {
if err != nil {
t.Fatalf("sqlmock.New: %v", err)
}
prevDB := db.DB
db.DB = mockDB
t.Cleanup(func() { mockDB.Close() })
t.Cleanup(func() { mockDB.Close(); db.DB = prevDB })
return mock
}

View File

@ -18,8 +18,9 @@ func setupLivenessTestDB(t *testing.T) sqlmock.Sqlmock {
if err != nil {
t.Fatalf("failed to create sqlmock: %v", err)
}
prevDB := db.DB
db.DB = mockDB
t.Cleanup(func() { mockDB.Close() })
t.Cleanup(func() { mockDB.Close(); db.DB = prevDB })
return mock
}

View File

@ -24,8 +24,9 @@ func setupTestDB(t *testing.T) sqlmock.Sqlmock {
if err != nil {
t.Fatalf("failed to create sqlmock: %v", err)
}
prevDB := db.DB
db.DB = mockDB
t.Cleanup(func() { mockDB.Close() })
t.Cleanup(func() { mockDB.Close(); db.DB = prevDB })
return mock
}