@@ -1349,24 +1349,30 @@ func x11EchoSession(ctx context.Context, t *testing.T, clt *tracessh.Client) x11
1349
1349
os .Remove (tmpFile .Name ())
1350
1350
})
1351
1351
1352
- // type 'printenv DISPLAY > /path/to/tmp/file' into the session (dumping the value of DISPLAY into the temp file)
1353
- _ , err = keyboard .Write ([]byte (fmt .Sprintf ("printenv %v >> %s\n \r " , x11 .DisplayEnv , tmpFile .Name ())))
1354
- require .NoError (t , err )
1352
+ // Reading the display may fail if the session is not fully initialized
1353
+ // and the write to stdin is swallowed.
1354
+ display := make (chan string , 1 )
1355
+ require .EventuallyWithT (t , func (t * assert.CollectT ) {
1356
+ // enter 'printenv DISPLAY > /path/to/tmp/file' into the session (dumping the value of DISPLAY into the temp file)
1357
+ _ , err = keyboard .Write ([]byte (fmt .Sprintf ("printenv %v > %s\n \r " , x11 .DisplayEnv , tmpFile .Name ())))
1358
+ assert .NoError (t , err )
1355
1359
1356
- // wait for the output
1357
- var display string
1358
- require .Eventually (t , func () bool {
1359
- output , err := os .ReadFile (tmpFile .Name ())
1360
- if err == nil && len (output ) != 0 {
1361
- display = strings .TrimSpace (string (output ))
1362
- return true
1363
- }
1364
- return false
1365
- }, 10 * time .Second , 100 * time .Millisecond , "failed to read display" )
1360
+ assert .Eventually (t , func () bool {
1361
+ output , err := os .ReadFile (tmpFile .Name ())
1362
+ if err == nil && len (output ) != 0 {
1363
+ select {
1364
+ case display <- strings .TrimSpace (string (output )):
1365
+ default :
1366
+ }
1367
+ return true
1368
+ }
1369
+ return false
1370
+ }, time .Second , 100 * time .Millisecond , "failed to read display" )
1371
+ }, 10 * time .Second , 1 * time .Second )
1366
1372
1367
1373
// Make a new connection to the XServer proxy, the client
1368
1374
// XServer should echo back anything written on it.
1369
- serverDisplay , err := x11 .ParseDisplay (display )
1375
+ serverDisplay , err := x11 .ParseDisplay (<- display )
1370
1376
require .NoError (t , err )
1371
1377
1372
1378
return serverDisplay
0 commit comments