Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd66b45

Browse files
committed
another attempt to fix window stest
1 parent2cbb597 commitdd66b45

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

‎agent/agent_test.go

Lines changed: 15 additions & 25 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,22 +325,15 @@ 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+
gofunc() {
331+
<-ctx.Done()
332+
_=session.Close()
333+
}()
328334

329335
s:=bufio.NewScanner(stdout)
330-
out:=make(chanstring)
331-
testutil.Go(t,func() {
332-
fors.Scan() {
333-
select {
334-
caseout<-s.Text():
335-
case<-ctx.Done():
336-
return
337-
}
338-
}
339-
})
340336

341-
// Until we have gotten the first result, the shell may spit out some data.
342-
first:=true
343337
//nolint:paralleltest // These tests need to run sequentially.
344338
fork,partialV:=rangemap[string]string{
345339
"CODER":"true",// From the agent.
@@ -350,21 +344,17 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
350344
} {
351345
t.Run(k,func(t*testing.T) {
352346
echoEnv(t,stdin,k)
353-
iffirst {
354-
for {
355-
s:=testutil.RequireRecvCtx(ctx,t,out)
356-
t.Logf("%s=%s",k,s)
357-
s=strings.TrimSpace(s)
358-
ifstrings.Contains(s,partialV) {
359-
first=false
360-
return
361-
}
347+
// Windows is unreliable, so keep scanning until we find a match.
348+
fors.Scan() {
349+
got:=strings.TrimSpace(s.Text())
350+
t.Logf("%s=%s",k,got)
351+
ifstrings.Contains(got,partialV) {
352+
break
362353
}
363354
}
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)
355+
iferr:=s.Err();!errors.Is(err,io.EOF) {
356+
require.NoError(t,err)
357+
}
368358
})
369359
}
370360
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp