rpc | put the timer out of the loop

This commit is contained in:
ucwong 2020-04-02 14:04:20 +00:00
parent 9759ac7816
commit e7354f6bc0

View file

@ -231,6 +231,8 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
sendResponse <-chan time.Time sendResponse <-chan time.Time
wantPong string wantPong string
) )
timer := time.NewTimer(200 * time.Millisecond)
defer timer.Stop()
for { for {
select { select {
case _, open := <-sendPing: case _, open := <-sendPing:
@ -247,8 +249,6 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
t.Errorf("got pong with wrong data %q", data) t.Errorf("got pong with wrong data %q", data)
} }
wantPong = "" wantPong = ""
timer := time.NewTimer(200 * time.Millisecond)
defer timer.Stop()
sendResponse = timer.C sendResponse = timer.C
case <-sendResponse: case <-sendResponse:
t.Logf("server sending response") t.Logf("server sending response")