test: the systemd startup gate asserts serve-after-barrier in process (no fence exit) and a moved source's exit 78

Fixes #572.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-24 18:35:38 -08:00
1 parent 7a14a0fd33
commit 5046436c8b
1 file changed
+74 -16
@@ -161,31 +161,41 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) {
if firstPID == "0" {
t.Fatal("returning unit did not start a real process")
}
// Existing assignment wait is30s. This is an outer failed-run guard, not
// an injected success delay or a replacement product deadline.
waitGAP1(t, "GAP-1: first startup never exited75; stayed alive non-serving", 45*time.Second, func() bool {
s := gap1Unit(t, unit)
// The returning process waits in process for the master's barrier and
// serves after it, with no fence exit and no restart (the startup wait,
// #535): first it reports the barrier as its MasterWait, never serving.
var barrierMs int64
waitGAP1(t, "returning unit never reported the master's barrier", 30*time.Second, func() bool {
if gap1Operational(t, statusAddr, volume) {
t.Fatal("fixture returned before the expired-grant barrier: cannot count this as a startup-timeout red")
t.Fatal("the returning unit served before reporting a barrier wait: an expired lease was re-granted without the barrier")
}
if s["ExecMainStatus"] == "75" {
if s := gap1Unit(t, unit); s["MainPID"] != firstPID {
t.Fatalf("the returning unit exited while waiting for the barrier: %+v", s)
}
if w := gap1MasterWait(t, statusAddr, volume); w.Reason == "barrier" && w.UntilMs > 0 {
barrierMs = w.UntilMs
t.Logf("captured master wait: reason=%s until=%d", w.Reason, w.UntilMs)
return true
}
if s["MainPID"] != "0" && s["MainPID"] != firstPID {
t.Fatalf("restart without captured75: %+v", s)
}
return false
})
waitGAP1(t, "systemd did not restart/regrant/attach", 100*time.Second, func() bool {
// Then the same process serves: not before the barrier, and within the
// startup wait's bound (barrier + 30 s; the outer guard adds slack).
waitGAP1(t, "the returning unit never served after the barrier", 75*time.Second, func() bool {
s := gap1Unit(t, unit)
n, e := strconv.Atoi(s["NRestarts"])
if e != nil {
t.Fatalf("invalid captured NRestarts: %+v", s)
if s["MainPID"] != firstPID || s["NRestarts"] != "0" {
t.Fatalf("the returning unit restarted (a fence exit) instead of serving in process: %+v", s)
}
if n > 2 {
t.Fatalf("barrier retry exceeded three total launches: %+v", s)
if !gap1Operational(t, statusAddr, volume) {
return false
}
return n >= 1 && s["MainPID"] != "0" && s["MainPID"] != firstPID && gap1Operational(t, statusAddr, volume)
if now := time.Now().UnixMilli(); now < barrierMs {
t.Fatalf("served at %d, before the master's barrier %d", now, barrierMs)
}
if late := time.Now().UnixMilli() - barrierMs; late > 30_000 {
t.Fatalf("served %d ms after the barrier: past the startup wait's 30 s bound", late)
}
return true
})
after, err := gap1ReadHead(t, remote)
if err != nil || after.Gen <= before.Gen || after.Holder != before.Holder || after.Epoch != before.Epoch {
@@ -215,6 +225,54 @@ func TestSystemdExpiredStartupExits75ThenRegrantServes(t *testing.T) {
}
gap1PlannedStopDoesNotRestart(t, ws, unit, statusAddr, volume, after.Epoch, "r1", s["NRestarts"], s["InvocationID"])
gap1PrestartedTargetServesAfterMove(t, fixture, ws, remote, target, stem, filepath.Join(bin, "blockvolume"), args, root, volume, want)
gap1MovedSourceExits78(t, fixture, filepath.Join(bin, "blockvolume"), args, stem, statusAddr, volume)
}
// gap1MovedSourceExits78 is the negative case of the in-process wait: after
// the volume moved to another host, the old source started again learns the
// move and exits 78 (final), which the unit's RestartPreventExitStatus keeps
// from restarting; it never serves.
func gap1MovedSourceExits78(t *testing.T, fixture *gap1Fixture, exe string, args []string, stem, statusAddr, volume string) {
t.Helper()
unit := stem + "-moved-source"
fixture.start(t, unit, true, exe, args...)
waitGAP1(t, "the moved-away source never exited 78", 90*time.Second, func() bool {
if gap1Operational(t, statusAddr, volume) {
t.Fatal("the moved-away source served")
}
s := gap1Unit(t, unit)
if s["ExecMainStatus"] == "75" {
t.Fatalf("the moved-away source exited 75 (retry) instead of 78 (moved): %+v", s)
}
return s["ExecMainStatus"] == "78" && s["MainPID"] == "0"
})
time.Sleep(7 * time.Second) // past RestartSec: a restart would have happened
if s := gap1Unit(t, unit); s["NRestarts"] != "0" || s["MainPID"] != "0" {
t.Fatalf("systemd restarted the moved-away source after its exit 78: %+v", s)
}
}
// gap1MasterWait reads the volume's /status MasterWait (the startup wait's
// reason and the master's barrier time), zero when absent.
func gap1MasterWait(t *testing.T, addr, volume string) struct {
Reason string
UntilMs int64
} {
t.Helper()
var out struct {
MasterWait *struct {
Reason string
UntilMs int64
}
}
code, body, err := gap1StatusAt(addr, volume, "/status")
if err != nil || code != http.StatusOK || json.Unmarshal(body, &out) != nil || out.MasterWait == nil {
return struct {
Reason string
UntilMs int64
}{}
}
return *out.MasterWait
}
// Roots are deliberately independent of testing.TempDir: unknown unit cleanup