Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05c4c2e

Browse files
committed
test(agent): fix flake in TestAgent_Stats_SSH
Cause: stats are sampled per interval; starting an SSH shell without sending data can produce samples with session_count_ssh==1 but rx/tx==0, so the combined predicate never matches before timeout. Fix: write a small command to stdin right after session.Shell() to guarantee rx/tx>0 in the same stats window as the session, eliminating the flake. Change-Id: Ib9d2cf26e1328c2b6fe846a3054b983c02aff78d Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 6d39077 commit 05c4c2e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

agent/agent_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ func TestAgent_Stats_SSH(t *testing.T) {
149149
err = session.Shell()
150150
require.NoError(t, err)
151151

152+
// Nudge traffic so Rx/Tx bytes are non-zero in the same stats window.
153+
// Without writing anything, the shell may idle and stats samples can
154+
// report session_count_ssh without non-zero byte counts, which makes
155+
// the combined predicate below flaky.
156+
// Related: https://github.com/coder/internal/issues/505
157+
if runtime.GOOS == "windows" {
158+
_, _ = io.WriteString(stdin, "echo test\r\n")
159+
} else {
160+
_, _ = io.WriteString(stdin, "echo test\n")
161+
}
162+
152163
var s *proto.Stats
153164
require.Eventuallyf(t, func() bool {
154165
var ok bool

0 commit comments

Comments
 (0)