Skip to content

rpc: add missing timer.Stop calls in websocket tests #20863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 2, 2020
12 changes: 7 additions & 5 deletions rpc/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down