Skip to content

Commit b9895ac

Browse files
committed
another attempt to fix window stest
1 parent 2cbb597 commit b9895ac

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

agent/agent_test.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,12 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
324324
err = session.Start(command)
325325
require.NoError(t, err)
326326

327+
// Context is fine here since we're not doing a parallel subtest.
327328
ctx := testutil.Context(t, testutil.WaitLong)
329+
go func() {
330+
<-ctx.Done()
331+
_ = session.Close()
332+
}()
328333

329334
s := bufio.NewScanner(stdout)
330335
out := make(chan string)
@@ -338,8 +343,6 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
338343
}
339344
})
340345

341-
// Until we have gotten the first result, the shell may spit out some data.
342-
first := true
343346
//nolint:paralleltest // These tests need to run sequentially.
344347
for k, partialV := range map[string]string{
345348
"CODER": "true", // From the agent.
@@ -350,21 +353,15 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
350353
} {
351354
t.Run(k, func(t *testing.T) {
352355
echoEnv(t, stdin, k)
353-
if first {
354-
for {
355-
s := testutil.RequireRecvCtx(ctx, t, out)
356-
t.Logf("%s=%s", k, s)
357-
s = strings.TrimSpace(s)
358-
if strings.Contains(s, partialV) {
359-
first = false
360-
return
361-
}
356+
// Windows is unreliable, so keep scanning until we find a match.
357+
for s.Scan() {
358+
got := strings.TrimSpace(s.Text())
359+
t.Logf("%s=%s", k, got)
360+
if strings.Contains(got, partialV) {
361+
break
362362
}
363363
}
364-
s := testutil.RequireRecvCtx(ctx, t, out)
365-
t.Logf("%s=%s", k, s)
366-
s = strings.TrimSpace(s)
367-
require.Contains(t, s, partialV)
364+
require.NoError(t, s.Err())
368365
})
369366
}
370367
}

0 commit comments

Comments
 (0)