Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffae4ad

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

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

agent/agent_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"context"
77
"encoding/json"
8+
"errors"
89
"fmt"
910
"io"
1011
"math/rand"
@@ -324,7 +325,12 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
324325
err = session.Start(command)
325326
require.NoError(t, err)
326327

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

329335
s := bufio.NewScanner(stdout)
330336
out := make(chan string)
@@ -338,8 +344,6 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
338344
}
339345
})
340346

341-
// Until we have gotten the first result, the shell may spit out some data.
342-
first := true
343347
//nolint:paralleltest // These tests need to run sequentially.
344348
for k, partialV := range map[string]string{
345349
"CODER": "true", // From the agent.
@@ -350,21 +354,17 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
350354
} {
351355
t.Run(k, func(t *testing.T) {
352356
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-
}
357+
// Windows is unreliable, so keep scanning until we find a match.
358+
for s.Scan() {
359+
got := strings.TrimSpace(s.Text())
360+
t.Logf("%s=%s", k, got)
361+
if strings.Contains(got, partialV) {
362+
break
362363
}
363364
}
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)
365+
if err := s.Err(); !errors.Is(err, io.EOF) {
366+
require.NoError(t, err)
367+
}
368368
})
369369
}
370370
}

0 commit comments

Comments
 (0)