@@ -636,6 +636,8 @@ func TestSSH(t *testing.T) {
636
636
defer httpServer .Close ()
637
637
638
638
client , workspace , agentToken := setupWorkspaceForAgent (t , nil )
639
+ _ = agenttest .New (t , client .URL , agentToken )
640
+ coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
639
641
640
642
inv , root := clitest .New (t ,
641
643
"ssh" ,
@@ -644,32 +646,36 @@ func TestSSH(t *testing.T) {
644
646
"8222:" + httpServer .Listener .Addr ().String (),
645
647
)
646
648
clitest .SetupConfig (t , client , root )
647
- pty := ptytest .New (t ).Attach (inv )
648
- inv .Stderr = pty .Output ()
649
649
650
650
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
651
651
defer cancel ()
652
652
653
653
cmdDone := tGo (t , func () {
654
654
err := inv .WithContext (ctx ).Run ()
655
- assert .NoError (t , err , "ssh command failed" )
655
+ // fails because we cancel context to close
656
+ assert .Error (t , err , "ssh command should fail" )
656
657
})
657
658
658
- // Agent is still starting
659
- pty .ExpectMatch ("Waiting" )
660
-
661
- _ = agenttest .New (t , client .URL , agentToken )
662
- coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
663
-
664
- // Startup script has just finished
665
- pty .ExpectMatch (startupScriptPattern )
666
-
667
- // Download the test page
668
- pty .WriteLine ("curl localhost:8222" )
669
- pty .ExpectMatch ("hello world" )
659
+ require .Eventually (t , func () bool {
660
+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , "http://localhost:8222/" , nil )
661
+ if ! assert .NoError (t , err ) {
662
+ // true exits the loop.
663
+ return true
664
+ }
665
+ resp , err := http .DefaultClient .Do (req )
666
+ if err != nil {
667
+ t .Logf ("HTTP GET http://localhost:8222/ %s" , err )
668
+ return false
669
+ }
670
+ defer resp .Body .Close ()
671
+ body , err := io .ReadAll (resp .Body )
672
+ assert .NoError (t , err )
673
+ assert .EqualValues (t , "hello world" , body )
674
+ return true
675
+ }, testutil .WaitLong , testutil .IntervalFast )
670
676
671
677
// And we're done.
672
- pty . WriteLine ( "exit" )
678
+ cancel ( )
673
679
<- cmdDone
674
680
})
675
681
0 commit comments