@@ -348,6 +348,57 @@ func TestAgent_Session_TTY_Hushlogin(t *testing.T) {
348
348
require .NotContains (t , stdout .String (), wantNotMOTD , "should not show motd" )
349
349
}
350
350
351
+ func TestAgent_Session_TTY_FastCommandHasOutput (t * testing.T ) {
352
+ t .Parallel ()
353
+ if runtime .GOOS == "windows" {
354
+ // This might be our implementation, or ConPTY itself.
355
+ // It's difficult to find extensive tests for it, so
356
+ // it seems like it could be either.
357
+ t .Skip ("ConPTY appears to be inconsistent on Windows." )
358
+ }
359
+
360
+ // This test is here to prevent regressions where quickly executing
361
+ // commands (with TTY) don't flush their output to the SSH session.
362
+ //
363
+ // See: https://github.com/coder/coder/issues/6656
364
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
365
+ defer cancel ()
366
+ //nolint:dogsled
367
+ conn , _ , _ , _ , _ := setupAgent (t , agentsdk.Metadata {}, 0 )
368
+ sshClient , err := conn .SSHClient (ctx )
369
+ require .NoError (t , err )
370
+ defer sshClient .Close ()
371
+
372
+ ptty := ptytest .New (t )
373
+
374
+ var stdout bytes.Buffer
375
+ // NOTE(mafredri): Increase iterations to increase chance of failure,
376
+ // assuming bug is present.
377
+ // Using 1000 iterations is basically a guaranteed failure (but let's
378
+ // not increase test times needlessly).
379
+ for i := 0 ; i < 5 ; i ++ {
380
+ func () {
381
+ stdout .Reset ()
382
+
383
+ session , err := sshClient .NewSession ()
384
+ require .NoError (t , err )
385
+ defer session .Close ()
386
+ err = session .RequestPty ("xterm" , 128 , 128 , ssh.TerminalModes {})
387
+ require .NoError (t , err )
388
+
389
+ session .Stdout = & stdout
390
+ session .Stderr = ptty .Output ()
391
+ session .Stdin = ptty .Input ()
392
+ err = session .Start ("echo wazzup" )
393
+ require .NoError (t , err )
394
+
395
+ err = session .Wait ()
396
+ require .NoError (t , err )
397
+ require .Contains (t , stdout .String (), "wazzup" , "should output greeting" )
398
+ }()
399
+ }
400
+ }
401
+
351
402
//nolint:paralleltest // This test reserves a port.
352
403
func TestAgent_TCPLocalForwarding (t * testing.T ) {
353
404
random , err := net .Listen ("tcp" , "127.0.0.1:0" )
0 commit comments