From a7fe35af2523809178aea0c8d55482207c341a04 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:51:55 +1100 Subject: [PATCH] fix: use `netstat` over `ss` when testing unix socket (#16103) Closes https://github.com/coder/internal/issues/274. `TestSSH/RemoteForwardUnixSocket` previously used `ss` for confirming if a socket was listening. `ss` isn't available on macOS, causing the test to flake. The test previously passed on macOS as a 2 could always be read on the SSH connection, presumably reading it as part of some escape sequence? I confirmed the test passed on Linux if you comment out the `ss` command, the pty would always read a sequence ending in `[?2`. --- cli/ssh_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index 4fd52971df..8006297f0c 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -1146,9 +1146,8 @@ func TestSSH(t *testing.T) { // started and accepting input on stdin. _ = pty.Peek(ctx, 1) - // Download the test page - pty.WriteLine(fmt.Sprintf("ss -xl state listening src %s | wc -l", remoteSock)) - pty.ExpectMatch("2") + pty.WriteLine(fmt.Sprintf("netstat -an | grep -q %s; echo \"returned $?\"", remoteSock)) + pty.ExpectMatchContext(ctx, "returned 0") // And we're done. pty.WriteLine("exit")