From f7b29ec942d91aee420d89d976ed94257398764e Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 3 Apr 2020 04:08:45 +0800 Subject: [PATCH] rpc: add missing timer.Stop calls in websocket tests (#20863) --- rpc/websocket_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rpc/websocket_test.go b/rpc/websocket_test.go index f2a8438d7..f54fc3cd5 100644 --- a/rpc/websocket_test.go +++ b/rpc/websocket_test.go @@ -142,6 +142,7 @@ func TestClientWebsocketPing(t *testing.T) { // Wait for the subscription result. timeout := time.NewTimer(5 * time.Second) + defer timeout.Stop() for { select { case err := <-sub.Err(): @@ -227,9 +228,11 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <- // Write messages. var ( - sendResponse <-chan time.Time - wantPong string + wantPong string + timer = time.NewTimer(0) ) + defer timer.Stop() + <-timer.C for { select { case _, open := <-sendPing: @@ -246,11 +249,10 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <- t.Errorf("got pong with wrong data %q", data) } wantPong = "" - sendResponse = time.NewTimer(200 * time.Millisecond).C - case <-sendResponse: + timer.Reset(200 * time.Millisecond) + case <-timer.C: t.Logf("server sending response") conn.WriteMessage(websocket.TextMessage, []byte(subNotify)) - sendResponse = nil case <-shutdown: conn.Close() return