From 73c742a3ce3579c1d8bdcc52b565674d23b2e067 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Fri, 27 Jun 2025 15:27:38 +0400 Subject: [PATCH] chore: test eviction with used ports (#18566) relates to #18263 Modifies the eviction unit test to include a port that is already claimed by an external process. --- agent/agentssh/x11_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/agent/agentssh/x11_test.go b/agent/agentssh/x11_test.go index c8e3dd45c1..4946fa2ac0 100644 --- a/agent/agentssh/x11_test.go +++ b/agent/agentssh/x11_test.go @@ -162,10 +162,17 @@ func TestServer_X11_EvictionLRU(t *testing.T) { c := sshClient(t, ln.Addr().String()) + // block off one port to test x11Forwarder evicts at highest port, not number of listeners. + externalListener, err := inproc.Listen("tcp", + fmt.Sprintf("localhost:%d", agentssh.X11StartPort+agentssh.X11DefaultDisplayOffset+1)) + require.NoError(t, err) + defer externalListener.Close() + // Calculate how many simultaneous X11 sessions we can create given the // configured port range. + startPort := agentssh.X11StartPort + agentssh.X11DefaultDisplayOffset - maxSessions := agentssh.X11MaxPort - startPort + 1 + maxSessions := agentssh.X11MaxPort - startPort + 1 - 1 // -1 for the blocked port require.Greater(t, maxSessions, 0, "expected a positive maxSessions value") // shellSession holds references to the session and its standard streams so