Skip to content

Commit f7b29ec

Browse files
authored
rpc: add missing timer.Stop calls in websocket tests (#20863)
1 parent f98caba commit f7b29ec

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎rpc/websocket_test.go‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ func TestClientWebsocketPing(t *testing.T) {
142142

143143
// Wait for the subscription result.
144144
timeout := time.NewTimer(5 * time.Second)
145+
defer timeout.Stop()
145146
for {
146147
select {
147148
case err := <-sub.Err():
@@ -227,9 +228,11 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
227228

228229
// Write messages.
229230
var (
230-
sendResponse <-chan time.Time
231-
wantPong string
231+
wantPong string
232+
timer = time.NewTimer(0)
232233
)
234+
defer timer.Stop()
235+
<-timer.C
233236
for {
234237
select {
235238
case _, open := <-sendPing:
@@ -246,11 +249,10 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
246249
t.Errorf("got pong with wrong data %q", data)
247250
}
248251
wantPong = ""
249-
sendResponse = time.NewTimer(200 * time.Millisecond).C
250-
case <-sendResponse:
252+
timer.Reset(200 * time.Millisecond)
253+
case <-timer.C:
251254
t.Logf("server sending response")
252255
conn.WriteMessage(websocket.TextMessage, []byte(subNotify))
253-
sendResponse = nil
254256
case <-shutdown:
255257
conn.Close()
256258
return

0 commit comments

Comments
 (0)