rpc/websocket_test | Add missing timer.Stop calls if response timer is not nil

This commit is contained in:
ucwong 2020-04-02 09:33:05 +00:00
parent f15849cf00
commit e0971d47db

View file

@ -142,6 +142,7 @@ func TestClientWebsocketPing(t *testing.T) {
// Wait for the subscription result. // Wait for the subscription result.
timeout := time.NewTimer(5 * time.Second) timeout := time.NewTimer(5 * time.Second)
defer timeout.Stop()
for { for {
select { select {
case err := <-sub.Err(): case err := <-sub.Err():
@ -247,6 +248,11 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
} }
wantPong = "" wantPong = ""
sendResponse = time.NewTimer(200 * time.Millisecond).C sendResponse = time.NewTimer(200 * time.Millisecond).C
defer func() {
if sendResponse != nil {
sendResponse.Stop()
}
}()
case <-sendResponse: case <-sendResponse:
t.Logf("server sending response") t.Logf("server sending response")
conn.WriteMessage(websocket.TextMessage, []byte(subNotify)) conn.WriteMessage(websocket.TextMessage, []byte(subNotify))