From 1ff58a3de734f93351111775e64a7fafd99cb683 Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Thu, 7 Oct 2021 16:39:43 -0400 Subject: [PATCH] Update docs, remove needless condition check --- pkg/liveshare/port_forwarder.go | 2 +- pkg/liveshare/session.go | 4 ++-- pkg/liveshare/session_test.go | 6 +----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/liveshare/port_forwarder.go b/pkg/liveshare/port_forwarder.go index 43b6da805..2649abd3c 100644 --- a/pkg/liveshare/port_forwarder.go +++ b/pkg/liveshare/port_forwarder.go @@ -163,7 +163,7 @@ func (fwd *PortForwarder) handleConnection(ctx context.Context, id channelID, co connReader io.Reader = conn ) - // If we the port forwader has been configured to keep the session alive + // If the forwader has been configured to keep the session alive // it will monitor the I/O and notify the session of the traffic. if fwd.keepAlive { channelReader = newTrafficMonitor(channelReader, fwd.session, "output") diff --git a/pkg/liveshare/session.go b/pkg/liveshare/session.go index ca01d4cf3..13558f911 100644 --- a/pkg/liveshare/session.go +++ b/pkg/liveshare/session.go @@ -103,8 +103,8 @@ func (s *Session) StartSSHServer(ctx context.Context) (int, string, error) { return port, response.User, nil } -// heartbeat ticks every interval and sends a signal to the Live Share host to keep -// the connection alive if there is a reason to do so. +// heartbeat runs until context cancellation, periodically checking whether there is a +// reason to keep the connection alive, and if so, notifying the Live Share host to do so. func (s *Session) heartbeat(ctx context.Context, interval time.Duration) { ticker := time.NewTicker(interval) defer ticker.Stop() diff --git a/pkg/liveshare/session_test.go b/pkg/liveshare/session_test.go index e6ebb3645..0e10644fb 100644 --- a/pkg/liveshare/session_test.go +++ b/pkg/liveshare/session_test.go @@ -230,16 +230,12 @@ func TestInvalidHostKey(t *testing.T) { func TestKeepAliveNonBlocking(t *testing.T) { session := &Session{keepAliveReason: make(chan string, 1)} - var i int - for ; i < 2; i++ { + for i := 0; i < 2; i++ { session.keepAlive("io") } // if keepAlive blocks, we'll never reach this and timeout the test // timing out - if i != 2 { - t.Errorf("unexpected iteration account, expected: 2, got: %d", i) - } } func TestNotifyHostOfActivity(t *testing.T) {