Skip to content

Commit 1286904

Browse files
authored
test(agent): improve TestAgent_Session_TTY_MOTD_Update (#10385)
1 parent 09f7b8e commit 1286904

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

agent/agent_test.go

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ func TestAgent_Session_TTY_MOTD(t *testing.T) {
380380
}
381381
}
382382

383+
//nolint:tparallel // Sub tests need to run sequentially.
383384
func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {
384385
t.Parallel()
385386
if runtime.GOOS == "windows" {
@@ -439,33 +440,38 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {
439440
}
440441
//nolint:dogsled // Allow the blank identifiers.
441442
conn, client, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, setSBInterval)
442-
for _, test := range tests {
443+
444+
sshClient, err := conn.SSHClient(ctx)
445+
require.NoError(t, err)
446+
t.Cleanup(func() {
447+
_ = sshClient.Close()
448+
})
449+
450+
//nolint:paralleltest // These tests need to swap the banner func.
451+
for i, test := range tests {
443452
test := test
444-
// Set new banner func and wait for the agent to call it to update the
445-
// banner.
446-
ready := make(chan struct{}, 2)
447-
client.SetServiceBannerFunc(func() (codersdk.ServiceBannerConfig, error) {
448-
select {
449-
case ready <- struct{}{}:
450-
default:
451-
}
452-
return test.banner, nil
453-
})
454-
<-ready
455-
<-ready // Wait for two updates to ensure the value has propagated.
453+
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
454+
// Set new banner func and wait for the agent to call it to update the
455+
// banner.
456+
ready := make(chan struct{}, 2)
457+
client.SetServiceBannerFunc(func() (codersdk.ServiceBannerConfig, error) {
458+
select {
459+
case ready <- struct{}{}:
460+
default:
461+
}
462+
return test.banner, nil
463+
})
464+
<-ready
465+
<-ready // Wait for two updates to ensure the value has propagated.
456466

457-
sshClient, err := conn.SSHClient(ctx)
458-
require.NoError(t, err)
459-
t.Cleanup(func() {
460-
_ = sshClient.Close()
461-
})
462-
session, err := sshClient.NewSession()
463-
require.NoError(t, err)
464-
t.Cleanup(func() {
465-
_ = session.Close()
466-
})
467+
session, err := sshClient.NewSession()
468+
require.NoError(t, err)
469+
t.Cleanup(func() {
470+
_ = session.Close()
471+
})
467472

468-
testSessionOutput(t, session, test.expected, test.unexpected, nil)
473+
testSessionOutput(t, session, test.expected, test.unexpected, nil)
474+
})
469475
}
470476
}
471477

0 commit comments

Comments
 (0)