X Tutup
Skip to content

Commit c70e2a3

Browse files
authored
allow 2 go routines to send
1 parent d60419b commit c70e2a3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/liveshare/port_forwarder_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
X Tutup