From e2a7bbb90bcd1077bd785236a4915c899ed059d8 Mon Sep 17 00:00:00 2001 From: Jim Wordelman Date: Wed, 19 Aug 2026 19:55:40 -0700 Subject: [PATCH] fix(dolt): remove dead decoy-listener test code, use retry-safe schema init under 10-way contention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../dolt/initschema_multiprocess_test.go | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/internal/storage/dolt/initschema_multiprocess_test.go b/internal/storage/dolt/initschema_multiprocess_test.go index 1f5c10c95..1a3fbfc04 100644 --- a/internal/storage/dolt/initschema_multiprocess_test.go +++ b/internal/storage/dolt/initschema_multiprocess_test.go @@ -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 }) }