@@ -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,31 @@ 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
+ resp , err := http . Get ( "http://localhost:8222/ " )
661
+ if err != nil {
662
+ t . Logf ( "HTTP GET http://localhost:8222/ %s" , err )
663
+ return false
664
+ }
665
+ defer resp . Body . Close ()
666
+ body , err := io . ReadAll ( resp . Body )
667
+ require . NoError ( t , err )
668
+ require . EqualValues ( t , "hello world" , body )
669
+ return true
670
+ }, testutil . WaitLong , testutil . IntervalFast )
670
671
671
672
// And we're done.
672
- pty . WriteLine ( "exit" )
673
+ cancel ( )
673
674
<- cmdDone
674
675
})
675
676
0 commit comments