From f93d9a10c1a95e5713035cffcebb1044010bab1d Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 23 Oct 2023 14:39:26 +0000 Subject: [PATCH 1/2] test(agent): improve TestAgent_Session_TTY_MOTD_Update --- agent/agent_test.go | 53 +++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/agent/agent_test.go b/agent/agent_test.go index bf71c4f1638f9..e42a662401452 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -434,33 +434,38 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) { } //nolint:dogsled // Allow the blank identifiers. conn, client, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, setSBInterval) - for _, test := range tests { + + sshClient, err := conn.SSHClient(ctx) + require.NoError(t, err) + t.Cleanup(func() { + _ = sshClient.Close() + }) + + //nolint:paralleltest // These tests need to swap the banner func. + for i, test := range tests { test := test - // Set new banner func and wait for the agent to call it to update the - // banner. - ready := make(chan struct{}, 2) - client.SetServiceBannerFunc(func() (codersdk.ServiceBannerConfig, error) { - select { - case ready <- struct{}{}: - default: - } - return test.banner, nil - }) - <-ready - <-ready // Wait for two updates to ensure the value has propagated. + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + // Set new banner func and wait for the agent to call it to update the + // banner. + ready := make(chan struct{}, 2) + client.SetServiceBannerFunc(func() (codersdk.ServiceBannerConfig, error) { + select { + case ready <- struct{}{}: + default: + } + return test.banner, nil + }) + <-ready + <-ready // Wait for two updates to ensure the value has propagated. - sshClient, err := conn.SSHClient(ctx) - require.NoError(t, err) - t.Cleanup(func() { - _ = sshClient.Close() - }) - session, err := sshClient.NewSession() - require.NoError(t, err) - t.Cleanup(func() { - _ = session.Close() - }) + session, err := sshClient.NewSession() + require.NoError(t, err) + t.Cleanup(func() { + _ = session.Close() + }) - testSessionOutput(t, session, test.expected, test.unexpected, nil) + testSessionOutput(t, session, test.expected, test.unexpected, nil) + }) } } From 61eb4dbc614c75832e9a2120dc569e04997c4a53 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Mon, 23 Oct 2023 15:30:27 +0000 Subject: [PATCH 2/2] fix lint --- agent/agent_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/agent/agent_test.go b/agent/agent_test.go index e42a662401452..0eecc4223e7d6 100644 --- a/agent/agent_test.go +++ b/agent/agent_test.go @@ -375,6 +375,7 @@ func TestAgent_Session_TTY_MOTD(t *testing.T) { } } +//nolint:tparallel // Sub tests need to run sequentially. func TestAgent_Session_TTY_MOTD_Update(t *testing.T) { t.Parallel() if runtime.GOOS == "windows" {