Skip to content

Commit c403a99

Browse files
committed
Stop the peek-activity test blaming the pty's own delivery on the peek
TestPeekDoesNotCountAsActivityInTheSession took its baseline the moment the echo became findable in the ring, which can be one chunk of several. Every chunk read back from the pty moves LastActive, so the pump finishing its delivery a millisecond later looked exactly like a peek that had touched the stamp — a race that never fired locally and fired on CI's first run. The property is unchanged and worth keeping; the measurement now waits for the session to actually go quiet before it starts. 40 runs under -race.
1 parent 27a1111 commit c403a99

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

‎internal/daemon/peek_test.go‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,39 @@ func TestPeekMintsNoRefAndLeavesNoSubscriber(t *testing.T) {
100100
})
101101
}
102102

103+
// quiet waits until a session's LastActive stops moving, and answers with it.
104+
//
105+
// Without this the case below measures the wrong thing. The stamp moves on
106+
// every chunk read back from the pty, and a pty round trip is the kernel's
107+
// business: peekTarget returns as soon as the echo is *findable* in the ring,
108+
// which can be one chunk of several. A baseline taken there and compared a
109+
// millisecond later catches the pump finishing its delivery and blames the
110+
// peek for it — which is exactly how this failed in CI and never once
111+
// locally.
112+
func quiet(t *testing.T, s *session.Session) time.Time {
113+
t.Helper()
114+
deadline := time.Now().Add(5 * time.Second)
115+
last := s.Info().LastActive
116+
for {
117+
time.Sleep(20 * time.Millisecond)
118+
now := s.Info().LastActive
119+
if now.Equal(last) {
120+
return now
121+
}
122+
if time.Now().After(deadline) {
123+
t.Fatal("the session never stopped producing output")
124+
}
125+
last = now
126+
}
127+
}
128+
103129
func TestPeekDoesNotCountAsActivityInTheSession(t *testing.T) {
104130
// The sessions list orders by LastActive by default, so a preview that
105131
// touched the stamp would sort the row under the pointer to the top of the
106132
// list the pointer is resting on.
107133
ts, reg := newTestServer(t)
108134
s := peekTarget(t, reg, "quiet")
109-
before := s.Info().LastActive
135+
before := quiet(t, s)
110136

111137
c := dial(t, ts)
112138
writeControl(t, c, wire.Hello{Ver: "test"})

0 commit comments

Comments
 (0)