host test: the replaced session's End may follow the new session's Status
TestInteractiveWorkerReaderGivesUpWhenReplacedDuringOpen failed on CI
with: frame 's' {"state":"starting"}, want an End. The fake door
reads each connection on its own goroutine into one frames channel.
The old session sends its End before the new session dials (run waits
on old.done), but the new connection's Status can still be queued
first. The test now skips Status frames before the old session's End
(wantEndAfterStatus) and still requires that End, reason replaced.
Witness: with a 200 ms delay before the door queues an End, the old
test fails with the CI message every time and the new one passes. 400
runs under load on DOCS-T1 did not reproduce it naturally.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+22
−1
internal/host/interactive_test.go+22 −1
CI passed — run details
diff --git a/internal/host/interactive_test.go b/internal/host/interactive_test.go| index c0c77a37c..4b1042433 100644 |
| --- a/internal/host/interactive_test.go |
| +++ b/internal/host/interactive_test.go |
| @@ -492,6 +492,23 @@ func (d *ixDoor) wantStatus(t *testing.T, state string) { |
| } |
| } |
| +// wantEndAfterStatus is wantEnd where another connection's Status frames |
| +// may come first on the shared channel; it skips those, nothing else. |
| +func (d *ixDoor) wantEndAfterStatus(t *testing.T) interactive.End { |
| + t.Helper() |
| + for { |
| + f := d.next(t) |
| + if f.kind == interactive.KindStatus { |
| + continue |
| + } |
| + var e interactive.End |
| + if f.kind != interactive.KindEnd || json.Unmarshal(f.payload, &e) != nil { |
| + t.Fatalf("frame %q %s, want an End", f.kind, f.payload) |
| + } |
| + return e |
| + } |
| +} |
| + |
| func (d *ixDoor) wantEnd(t *testing.T) interactive.End { |
| t.Helper() |
| f := d.next(t) |
| @@ -2099,7 +2116,11 @@ func TestInteractiveWorkerReaderGivesUpWhenReplacedDuringOpen(t *testing.T) { |
| waitFor(t, "the replacement", func() bool { return s.ctx.Err() != nil }) |
| } |
| wd.session() |
| - if e := wd.door.wantEnd(t); e.Reason != interactive.EndReplaced { |
| + // The door's frames come from both connections on one channel. The old |
| + // session sends its End before the new one dials, but each connection |
| + // is read on its own goroutine, so the new session's Status can be |
| + // queued first (#897: frame 's' {"state":"starting"}, want an End). |
| + if e := wd.door.wantEndAfterStatus(t); e.Reason != interactive.EndReplaced { |
| t.Fatalf("the old session's end %+v, want replaced", e) |
| } |
| waitFor(t, "the new session to start", func() bool { return len(wd.launch.calls()) == 1 }) |