@@ -324,7 +324,12 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
324
324
err = session .Start (command )
325
325
require .NoError (t , err )
326
326
327
+ // Context is fine here since we're not doing a parallel subtest.
327
328
ctx := testutil .Context (t , testutil .WaitLong )
329
+ go func () {
330
+ <- ctx .Done ()
331
+ _ = session .Close ()
332
+ }()
328
333
329
334
s := bufio .NewScanner (stdout )
330
335
out := make (chan string )
@@ -338,8 +343,6 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
338
343
}
339
344
})
340
345
341
- // Until we have gotten the first result, the shell may spit out some data.
342
- first := true
343
346
//nolint:paralleltest // These tests need to run sequentially.
344
347
for k , partialV := range map [string ]string {
345
348
"CODER" : "true" , // From the agent.
@@ -350,21 +353,15 @@ func TestAgent_Session_EnvironmentVariables(t *testing.T) {
350
353
} {
351
354
t .Run (k , func (t * testing.T ) {
352
355
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
362
362
}
363
363
}
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 ())
368
365
})
369
366
}
370
367
}
0 commit comments