rpc: simplify wsPingTestHandler

This commit is contained in:
Felix Lange 2020-04-02 17:38:13 +02:00 committed by GitHub
parent eb616bd618
commit 792c779892
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -228,11 +228,9 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
// Write messages. // Write messages.
var ( var (
sendResponse <-chan time.Time
wantPong string wantPong string
timer *Timer timer = time.NewTimer(0)
) )
timer := time.NewTimer(0)
defer timer.Stop() defer timer.Stop()
<-timer.C <-timer.C
for { for {
@ -252,11 +250,9 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
} }
wantPong = "" wantPong = ""
timer.Reset(200 * time.Millisecond) timer.Reset(200 * time.Millisecond)
sendResponse = timer.C case <-timer.C:
case <-sendResponse:
t.Logf("server sending response") t.Logf("server sending response")
conn.WriteMessage(websocket.TextMessage, []byte(subNotify)) conn.WriteMessage(websocket.TextMessage, []byte(subNotify))
sendResponse = nil
case <-shutdown: case <-shutdown:
conn.Close() conn.Close()
return return