From c70e2a345e403f4642bfef5223c69f6d10deb563 Mon Sep 17 00:00:00 2001 From: Bernardo <68619889+bchuecos@users.noreply.github.com> Date: Wed, 16 Mar 2022 20:34:51 +0000 Subject: [PATCH] allow 2 go routines to send --- pkg/liveshare/port_forwarder_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/liveshare/port_forwarder_test.go b/pkg/liveshare/port_forwarder_test.go index c01497c71..1a4526f2a 100644 --- a/pkg/liveshare/port_forwarder_test.go +++ b/pkg/liveshare/port_forwarder_test.go @@ -36,6 +36,7 @@ func TestPortForwarderStart(t *testing.T) { const port = 8000 sendNotification := make(chan portUpdateNotification) serverSharing := func(conn *jsonrpc2.Conn, req *jsonrpc2.Request) (interface{}, error) { + // Send the PortNotification that will be awaited on in session.StartSharing sendNotification <- portUpdateNotification{ PortNotification: PortNotification{ Port: port, @@ -74,7 +75,7 @@ func TestPortForwarderStart(t *testing.T) { _, _ = notif.conn.DispatchCall(context.Background(), "serverSharing.sharingSucceeded", notif) }() - done := make(chan error) + done := make(chan error, 2) go func() { done <- NewPortForwarder(session, "ssh", port, false).ForwardToListener(ctx, listen) }() @@ -88,16 +89,20 @@ func TestPortForwarderStart(t *testing.T) { } if conn == nil { done <- errors.New("failed to connect to forwarded port") + return } b := make([]byte, len("stream-data")) if _, err := conn.Read(b); err != nil && err != io.EOF { done <- fmt.Errorf("reading stream: %w", err) + return } if string(b) != "stream-data" { done <- fmt.Errorf("stream data is not expected value, got: %s", string(b)) + return } if _, err := conn.Write([]byte("new-data")); err != nil { done <- fmt.Errorf("writing to stream: %w", err) + return } done <- nil }()