| index 693ecda3c..eabb11d2f 100644 |
| --- a/cmd/moveprobe/main_test.go |
| +++ b/cmd/moveprobe/main_test.go |
| @@ -93,6 +93,8 @@ func shortTempDir(t *testing.T) string { |
| // fixture is one instance's world: its data directory (the flat layout, |
| // <dir>/h1.db and <dir>/h1/), a test S3 holding its store, and a control |
| // socket served by the platform's own schedule verbs over a registry. |
| +// Each test makes its own, and shares nothing else but the read-only |
| +// binPath, so every test runs in parallel. |
| type fixture struct { |
| t *testing.T |
| sockDir string |
| @@ -252,10 +254,16 @@ type probe struct { |
| // exec.Command(bin, "--socket", sock, "--db", dbPath) with the composed env. |
| // Its stdout and stderr are pipes, as the backend's tee makes them. |
| func (f *fixture) start(env map[string]string) *probe { |
| + f.t.Helper() |
| + return f.startBin(binPath, env) |
| +} |
| + |
| +// startBin is start with another build of moveprobe. |
| +func (f *fixture) startBin(bin string, env map[string]string) *probe { |
| f.t.Helper() |
| f.starts++ |
| p := &probe{t: f.t, sock: filepath.Join(f.sockDir, fmt.Sprintf("a%d.sock", f.starts)), out: &lockedBuffer{}, done: make(chan struct{})} |
| - p.cmd = exec.Command(binPath, "--socket", p.sock, "--db", f.db) |
| + p.cmd = exec.Command(bin, "--socket", p.sock, "--db", f.db) |
| p.cmd.Env = childEnv(env) |
| p.cmd.Stdout = p.out |
| p.cmd.Stderr = p.out |
| @@ -405,8 +413,9 @@ func (p *probe) report() reportDoc { |
| return r |
| } |
| |
| -// workerPIDs lists the pids whose command line starts with the test binary |
| -// and "worker" and names db. |
| +// workerPIDs lists the pids whose command line starts with a moveprobe |
| +// build the tests made (binPath, or a test's own, all named moveprobe*) and |
| +// "worker", and names db. |
| func workerPIDs(db string) []int { |
| var pids []int |
| ents, _ := os.ReadDir("/proc") |
| @@ -420,7 +429,7 @@ func workerPIDs(db string) []int { |
| continue |
| } |
| args := strings.Split(strings.TrimRight(string(raw), "\x00"), "\x00") |
| - if len(args) < 2 || args[0] != binPath || args[1] != "worker" || !strings.Contains(string(raw), db) { |
| + if len(args) < 2 || !strings.HasPrefix(filepath.Base(args[0]), "moveprobe") || args[1] != "worker" || !strings.Contains(string(raw), db) { |
| continue |
| } |
| if alive(pid) { |
| @@ -540,6 +549,7 @@ func (p *probe) fire(tm registry.Timer, token string) (int, string) { |
| // ---- the launch contract -------------------------------------------------- |
| |
| func TestMoveprobeLaunchContract(t *testing.T) { |
| + t.Parallel() |
| t.Run("the agent's variables and a store endpoint", func(t *testing.T) { |
| f := newFixture(t) |
| p := f.start(f.env) |
| @@ -765,10 +775,23 @@ func (o *oneConn) Addr() net.Addr { return o.c.LocalAddr() } |
| |
| // ---- the forked worker ------------------------------------------------------ |
| |
| +// The worker's grace is a minute in every build but this test's: it links |
| +// its own moveprobe with an 8 s grace (workerGraceOverride) and watches |
| +// that build's worker outlive its main, keep writing, and leave on its own |
| +// at the grace, as the shipped build does at a minute. |
| func TestMoveprobeWorkerOutlivesMain(t *testing.T) { |
| - t.Parallel() // a minute of waiting for the worker's own exit |
| + t.Parallel() |
| + if workerGrace != 60*time.Second || workerGraceOverride != "" || orphanGrace() != workerGrace { |
| + t.Fatalf("a plain build's worker grace is %s (const %s, override %q), want a minute", orphanGrace(), workerGrace, workerGraceOverride) |
| + } |
| + const grace = 8 * time.Second |
| + bin := filepath.Join(t.TempDir(), "moveprobe-grace") |
| + build := exec.Command("go", "build", "-ldflags", "-X main.workerGraceOverride="+grace.String(), "-o", bin, ".") |
| + if out, err := build.CombinedOutput(); err != nil { |
| + t.Fatalf("build moveprobe with an %s grace: %v\n%s", grace, err, out) |
| + } |
| f := newFixture(t) |
| - p := f.start(f.env) |
| + p := f.startBin(bin, f.env) |
| p.wait("/ready", http.StatusOK) |
| r := p.report() |
| if r.WorkerPID <= 0 || !alive(r.WorkerPID) { |
| @@ -798,22 +821,23 @@ func TestMoveprobeWorkerOutlivesMain(t *testing.T) { |
| t.Fatalf("the worker stopped writing after the main died: %d then %d rows", n0, n1) |
| } |
| |
| - // It exits on its own about a minute after its parent has gone. |
| - for alive(r.WorkerPID) && time.Since(killed) < 80*time.Second { |
| - time.Sleep(250 * time.Millisecond) |
| + // It exits on its own about its grace after its parent has gone. |
| + for alive(r.WorkerPID) && time.Since(killed) < grace+20*time.Second { |
| + time.Sleep(50 * time.Millisecond) |
| } |
| gone := time.Since(killed) |
| if alive(r.WorkerPID) { |
| t.Fatalf("the worker is still alive %s after the main died", gone.Round(time.Second)) |
| } |
| - if gone < 59*time.Second || gone > 70*time.Second { |
| - t.Errorf("the worker exited %s after the main died, want about 60s", gone.Round(time.Second)) |
| + if gone < grace-time.Second || gone > grace+10*time.Second { |
| + t.Errorf("the worker exited %s after the main died, want about %s", gone.Round(time.Second), grace) |
| } |
| } |
| |
| // ---- the failure switch --------------------------------------------------- |
| |
| func TestReadyFailsWhereTold(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| |
| // The installed state: a normal boot in uk, stopped, its worker killed |
| @@ -900,6 +924,7 @@ func TestReadyFailsWhereTold(t *testing.T) { |
| // ---- the report ----------------------------------------------------------- |
| |
| func TestReportCountsRowsByRegion(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| uk := f.start(f.env) |
| uk.wait("/ready", http.StatusOK) |
| @@ -991,6 +1016,7 @@ func TestReportCountsRowsByRegion(t *testing.T) { |
| // ---- the instance key ----------------------------------------------------- |
| |
| func TestReadyChecksBothKeys(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| p := f.start(f.env) |
| p.wait("/ready", http.StatusOK) |
| @@ -1061,6 +1087,7 @@ func allowInserts(t *testing.T, db, kind string) { |
| // TestReadyFollowsTheWorkersLastWrite: /ready is 200 only once a worker row |
| // has committed since this start and the worker's latest write succeeded. |
| func TestReadyFollowsTheWorkersLastWrite(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| seed := f.start(f.env) |
| seed.wait("/ready", http.StatusOK) |
| @@ -1113,6 +1140,7 @@ func TestReadyFollowsTheWorkersLastWrite(t *testing.T) { |
| } |
| |
| func TestAfterWriteExitsWhenItsRowFails(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| seed := f.start(f.env) |
| seed.wait("/ready", http.StatusOK) |
| @@ -1197,6 +1225,7 @@ func (r *failRows) Next(dest []driver.Value) error { |
| func init() { sql.Register("moveprobe-fail", failDriver{}) } |
| |
| func TestReportNeverAnswersPartial(t *testing.T) { |
| + t.Parallel() |
| report := func(t *testing.T, db *sql.DB) (int, string) { |
| t.Helper() |
| a := &app{db: db, filesDir: t.TempDir(), region: "uk", mode: modeNormal, storeErr: errors.New("store: not under test")} |
| @@ -1237,6 +1266,7 @@ func TestReportNeverAnswersPartial(t *testing.T) { |
| } |
| |
| func TestArmOnceReusesOneControlConnection(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| p := f.start(f.env) |
| p.wait("/ready", http.StatusOK) |
| @@ -1254,6 +1284,7 @@ func TestArmOnceReusesOneControlConnection(t *testing.T) { |
| // TestReadyFailsWhenTheWorkerStops: a worker that has died, or has sent no |
| // status for 3 s, fails readiness, and the report says so. |
| func TestReadyFailsWhenTheWorkerStops(t *testing.T) { |
| + t.Parallel() |
| t.Run("the worker dies after its first good write", func(t *testing.T) { |
| f := newFixture(t) |
| p := f.start(f.env) |
| @@ -1301,6 +1332,7 @@ func TestReadyFailsWhenTheWorkerStops(t *testing.T) { |
| // store check per 5 s, however many requests arrive, and requests that land |
| // while a check is running share its result. |
| func TestReadyCoalescesTheStoreCheck(t *testing.T) { |
| + t.Parallel() |
| f := newFixture(t) |
| p := f.start(f.env) |
| p.wait("/ready", http.StatusOK) |