@@ -36,6 +36,7 @@ func TestPortForwarderStart(t *testing.T) {
3636 const port = 8000
3737 sendNotification := make (chan portUpdateNotification )
3838 serverSharing := func (conn * jsonrpc2.Conn , req * jsonrpc2.Request ) (interface {}, error ) {
39+ // Send the PortNotification that will be awaited on in session.StartSharing
3940 sendNotification <- portUpdateNotification {
4041 PortNotification : PortNotification {
4142 Port : port ,
@@ -74,7 +75,7 @@ func TestPortForwarderStart(t *testing.T) {
7475 _ , _ = notif .conn .DispatchCall (context .Background (), "serverSharing.sharingSucceeded" , notif )
7576 }()
7677
77- done := make (chan error )
78+ done := make (chan error , 2 )
7879 go func () {
7980 done <- NewPortForwarder (session , "ssh" , port , false ).ForwardToListener (ctx , listen )
8081 }()
@@ -88,16 +89,20 @@ func TestPortForwarderStart(t *testing.T) {
8889 }
8990 if conn == nil {
9091 done <- errors .New ("failed to connect to forwarded port" )
92+ return
9193 }
9294 b := make ([]byte , len ("stream-data" ))
9395 if _ , err := conn .Read (b ); err != nil && err != io .EOF {
9496 done <- fmt .Errorf ("reading stream: %w" , err )
97+ return
9598 }
9699 if string (b ) != "stream-data" {
97100 done <- fmt .Errorf ("stream data is not expected value, got: %s" , string (b ))
101+ return
98102 }
99103 if _ , err := conn .Write ([]byte ("new-data" )); err != nil {
100104 done <- fmt .Errorf ("writing to stream: %w" , err )
105+ return
101106 }
102107 done <- nil
103108 }()
0 commit comments