fix(dolt): remove dead decoy-listener test code, use retry-safe schema init under 10-way contention

Round-2 review (be-4oah9) found two blocking issues in
TestMultiProcessSchemaInit_DoltVerify:

1. The "hermetic regression test" decoy listener set
   BEADS_DOLT_SERVER_PORT to its own port, then immediately cleared it
   to "" on the next line before doltserver.Start ran — so the decoy
   was never actually exercised. Removed the dead block; kept the
   actual fix (clearing the ambient env var before Start) with a
   comment describing why it's needed instead of a non-functional
   simulation of it.

2. TestMultiProcessSchemaInit_DoltVerify failed reproducibly on a
   migration-lock-timeout distinct from round 1's port collision.
   Root cause: the test's 10 concurrent goroutines called the raw,
   single-attempt initSchemaOnDB instead of initSchemaOnDBWithRetry —
   the wrapper real bd processes use via store.go's initSchema
   specifically so contended GET_LOCK attempts converge instead of
   one unlucky waiter failing outright. Sibling file
   initschema_concurrent_test.go already uses the retry variant for
   the same kind of contention scenario.

Verified: TestMultiProcessSchemaInit_DoltVerify PASS x3 (incl. once
with ambient BEADS_DOLT_SERVER_PORT set, matching the reviewer's
environment), plus TestMultiProcessSchemaInit,
TestHelperMultiStore, TestMultiStoreConcurrent_{InProcess,Subprocess,
CloseIsolation} all PASS. gofmt/go vet clean.

refs be-4oah9, be-yzowm
This commit is contained in:
Jim Wordelman 2026-08-19 19:55:40 -07:00
commit e2a7bbb90b

View file

@ -6,7 +6,6 @@ import (
"context"
"database/sql"
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
@ -227,22 +226,16 @@ func TestMultiProcessSchemaInit_DoltVerify(t *testing.T) {
t.Setenv("BEADS_DOLT_SHARED_SERVER", "0")
t.Setenv("BEADS_DOLT_AUTO_START", "1")
// Regression coverage for a round-1 review finding: on shared hosts, an
// ambient BEADS_DOLT_SERVER_PORT left by an unrelated process pointed
// doltserver.Start at that process's port, and Start correctly refused to
// steal it — failing this test for a reason unrelated to schema init.
// Simulate that ambient pollution hermetically (independent of any real
// process on this host) with a decoy listener standing in for the
// unrelated server, so this test's own throwaway server must isolate
// itself from ambient port config the same way it already isolates
// BEADS_DOLT_SHARED_SERVER/BEADS_DOLT_AUTO_START above.
decoyLn, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("listen decoy: %v", err)
}
t.Cleanup(func() { _ = decoyLn.Close() })
t.Setenv("BEADS_DOLT_SERVER_PORT", strconv.Itoa(decoyLn.Addr().(*net.TCPAddr).Port))
t.Setenv("BEADS_DOLT_SERVER_PORT", "") // isolate: this test manages its own throwaway server
// Regression coverage for a round-1 review finding: BEADS_DOLT_SERVER_PORT
// is the top-priority, authoritative port source (see portSources in
// internal/doltserver/doltserver.go) — an ambient value left by an
// unrelated process on a shared host pointed doltserver.Start at that
// process's port, and Start correctly refused to steal it, failing this
// test for a reason unrelated to schema init. This test manages its own
// throwaway server, so it isolates itself from ambient port config the
// same way it already isolates BEADS_DOLT_SHARED_SERVER/
// BEADS_DOLT_AUTO_START above.
t.Setenv("BEADS_DOLT_SERVER_PORT", "")
state, err := doltserver.Start(beadsDir)
if err != nil {
@ -288,7 +281,12 @@ func TestMultiProcessSchemaInit_DoltVerify(t *testing.T) {
defer db.Close()
db.SetMaxOpenConns(2)
<-ready
_, err = initSchemaOnDB(egCtx, db)
// initSchemaOnDBWithRetry, not the raw initSchemaOnDB: real bd
// processes racing for the migration lock go through this same
// retry wrapper (store.go's initSchema), which exists precisely so
// contended GET_LOCK attempts converge instead of one unlucky
// waiter failing outright.
_, err = initSchemaOnDBWithRetry(egCtx, db)
return err
})
}