Staging suite: wait for the instance restart before scenario 8 goes on
carlos restart returns before the box cycles the instance (2-15 s later), so scenario 8 could reattach to the process about to stop and never reopen its stream, or the restart landed inside the next scenario. restartInstance opens a probe stream before the restart command and waits for it to end (draining closes every stream), then for a new process that holds a stream open, each bounded with a clear failure. Scenario 8 then follows with keep(), which reopens a cut stream. The local control now returns before the instance cycles, as carlos restart does; the old harness times out on it locally.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+70
−3
internal/headless/env_test.go+8 −1internal/headless/scenarios_test.go+62 −2
CI cancelled — superseded by a newer push — run details
CI log
=== prepare === ci-box: machine: aarch64, 32 CPUs, 62 GiB memory, kernel 7.0.0-1017-aws ci-box: python 3.12.3; Docker version 29.1.3, build 29.1.3-0ubuntu3~24.04.2 ci-box: user namespaces allowed: 233151 ci-box: cgroup: cgroup2fs ci-box: disk /home/ci/work/repos/oficina__equipo/wt/staging-restart-wait: Type Size Avail | ext4 96G 86G ci-box: disk /home/ci/.cache/equipo-ci-box: Type Size Avail | ext4 96G 86G ci-box: bwrap: fetched and verified in 0.3s ci-box: claude: fetched and verified in 3.7s ci-box: codex: fetched and verified in 3.4s ci-box: codex-code-mode-host: fetched and verified in 1.3s ci-box: libwrap: fetched and verified in 0.3s ci-box: socat: fetched and verified in 0.4s npm warn deprecated node-domexception@1.0.0: Use your platform's native DOMException instead ci-box: image pulled in 9.8s ci-box: pi: installed and verified in 7.4s ci-box: opencode: installed and verified in 1.9s ci-box: chromium 156.0.8078.79-1~deb13u1: 76 packages fetched, verified and unpacked in 9.8s ci-box: clone deepened in 5.2s ci-box: file times set from content: 3201 files, 211 directories ci-box: ready in 18.6s === copy === EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$' -count=1 ok amadan.net/oficina/equipo/internal/equipotest 0.141s === compile === go build ./... RASTRILLO='go run amadan.net/rastrillo/rastrillo/cmd/rastrillo' python3 scripts/ci-test.py compile + go build -tags testbuild ./... 1.2s + go list -export -test -tags testbuild -f ./... amadan: job cancelled — a newer push superseded it
diff --git a/internal/headless/env_test.go b/internal/headless/env_test.go| index 17b0a351..4e4fd8c5 100644 |
| --- a/internal/headless/env_test.go |
| +++ b/internal/headless/env_test.go |
| @@ -280,6 +280,13 @@ func localEnv(t *testing.T) (*Env, *thintest.Instance, *localRunner) { |
| r.inst = inst |
| cfg, state, root := r.cfg, r.cfg.StateDir, r.root |
| t.Cleanup(func() { r.stop(t) }) |
| + // Like carlos restart, the control returns before the instance cycles, |
| + // so scenario 8 has to wait for the restart itself. |
| + restartLater := func(t *testing.T) { |
| + done := make(chan struct{}) |
| + t.Cleanup(func() { <-done }) |
| + time.AfterFunc(time.Second, func() { defer close(done); inst.Restart(t) }) |
| + } |
| turns := 0 |
| env := &Env{ |
| Client: thintest.NewClient(inst.URL, token), |
| @@ -288,7 +295,7 @@ func localEnv(t *testing.T) (*Env, *thintest.Instance, *localRunner) { |
| StopRunner: r.stop, |
| KillRunner: r.kill, |
| RestartRunner: func(t *testing.T) { r.stop(t); r.start(t) }, |
| - RestartInst: func(t *testing.T) { inst.Restart(t) }, |
| + RestartInst: restartLater, |
| ResumeThreshold: 5 * time.Second, |
| turns: &turns, |
| BreakDesk: func(t *testing.T) { |
diff --git a/internal/headless/scenarios_test.go b/internal/headless/scenarios_test.go| index ea1b8b5d..5248deb4 100644 |
| --- a/internal/headless/scenarios_test.go |
| +++ b/internal/headless/scenarios_test.go |
| @@ -380,8 +380,9 @@ func scenarioInstanceRestart(t *testing.T, env *Env) { |
| sent := s.send(t, env.Slow) |
| s.waitTurn(t, sent.Turn.ID, wire.TurnRunning, wire.TurnReplied) |
| s.close() |
| - env.RestartInst(t) |
| - s.follow(t) |
| + s.restartInstance(t) |
| + // Reopen from the cursor, and again if anything still cuts the stream. |
| + s.keep() |
| turn := s.waitTurn(t, sent.Turn.ID, wire.TurnReplied, wire.TurnFailed) |
| if turn.State == wire.TurnFailed && turn.Reason == "" { |
| t.Fatal("failed without a reason") |
| @@ -404,6 +405,65 @@ func scenarioInstanceRestart(t *testing.T, env *Env) { |
| } |
| } |
| +// restartInstance restarts the instance and returns only once the old |
| +// process has stopped and a new one serves. The platform's restart command |
| +// returns before the box cycles the instance (2-15 s later on staging), so |
| +// a probe stream opened first marks the old process: draining closes every |
| +// stream. A draining process still answers briefly, but its new streams end |
| +// at once, so the new process is the one that holds a stream open. |
| +func (s *session) restartInstance(t *testing.T) { |
| + t.Helper() |
| + const stops, serves, hold = time.Minute, 90 * time.Second, 2 * time.Second |
| + var cursor int64 |
| + s.conv.Locked(func(c *thintest.Conversation) { cursor = c.Cursor }) |
| + probe, err := s.env.Client.Open(s.ctx, cursor) |
| + if err != nil { |
| + t.Fatalf("instance restart: open the probe stream: %v", err) |
| + } |
| + defer probe.Close() |
| + // A full event buffer would stall the reader before it sees the end. |
| + drain := func(st *thintest.Stream) { |
| + go func() { |
| + for range st.Events { |
| + } |
| + }() |
| + } |
| + drain(probe) |
| + issued := time.Now() |
| + s.env.RestartInst(t) |
| + select { |
| + case <-probe.Done: |
| + case <-time.After(stops): |
| + t.Fatalf("instance restart: the old instance still serves %v after the restart command returned", stops) |
| + } |
| + stopped := time.Now() |
| + deadline := stopped.Add(serves) |
| + for { |
| + ctx, cancel := context.WithTimeout(s.ctx, 30*time.Second) |
| + stream, err := s.env.Client.Open(ctx, cursor) |
| + held := false |
| + if err == nil { |
| + drain(stream) |
| + select { |
| + case <-stream.Done: |
| + case <-time.After(hold): |
| + held = true |
| + } |
| + stream.Close() |
| + } |
| + cancel() |
| + if held { |
| + break |
| + } |
| + if time.Now().After(deadline) { |
| + t.Fatalf("instance restart: no new instance holds a stream %v after the old one stopped (last error %v)", serves, err) |
| + } |
| + time.Sleep(500 * time.Millisecond) |
| + } |
| + t.Logf("instance restart: old instance stopped %v after the command, new one serving %v later", |
| + stopped.Sub(issued).Round(100*time.Millisecond), time.Since(stopped).Round(100*time.Millisecond)) |
| +} |
| + |
| // Coordinator cancel: the attempt's process is stopped, the draft |
| // discarded, the turn ends cancelled, and the next message is answered. |
| func scenarioCancel(t *testing.T, env *Env) { |