From f4f075cd9b24c14ba771785739e9863fbe422ad5 Mon Sep 17 00:00:00 2001 From: ucwong Date: Thu, 2 Apr 2020 14:35:45 +0000 Subject: [PATCH] rpc : new timer when timer is nil and stop when not nil --- rpc/websocket_test.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rpc/websocket_test.go b/rpc/websocket_test.go index fe41efe3ae..b79597cdf1 100644 --- a/rpc/websocket_test.go +++ b/rpc/websocket_test.go @@ -230,9 +230,14 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <- var ( sendResponse <-chan time.Time wantPong string + timer *Timer ) - timer := time.NewTimer(200 * time.Millisecond) - defer timer.Stop() + //timer := time.NewTimer(200 * time.Millisecond) + defer func() { + if timer != nil { + timer.Stop() + } + }() for { select { case _, open := <-sendPing: @@ -249,7 +254,11 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <- t.Errorf("got pong with wrong data %q", data) } wantPong = "" - timer.Reset(200 * time.Millisecond) + if timer == nil { + timer = time.NewTimer(200 * time.Millisecond) + } else { + timer.Reset(200 * time.Millisecond) + } sendResponse = timer.C case <-sendResponse: t.Logf("server sending response")