mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rpc : new timer when timer is nil and stop when not nil
This commit is contained in:
parent
8a40a8f0c6
commit
f4f075cd9b
1 changed files with 12 additions and 3 deletions
|
|
@ -230,9 +230,14 @@ func wsPingTestHandler(t *testing.T, conn *websocket.Conn, shutdown, sendPing <-
|
||||||
var (
|
var (
|
||||||
sendResponse <-chan time.Time
|
sendResponse <-chan time.Time
|
||||||
wantPong string
|
wantPong string
|
||||||
|
timer *Timer
|
||||||
)
|
)
|
||||||
timer := time.NewTimer(200 * time.Millisecond)
|
//timer := time.NewTimer(200 * time.Millisecond)
|
||||||
defer timer.Stop()
|
defer func() {
|
||||||
|
if timer != nil {
|
||||||
|
timer.Stop()
|
||||||
|
}
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case _, open := <-sendPing:
|
case _, open := <-sendPing:
|
||||||
|
|
@ -249,7 +254,11 @@ 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 = ""
|
||||||
|
if timer == nil {
|
||||||
|
timer = time.NewTimer(200 * time.Millisecond)
|
||||||
|
} else {
|
||||||
timer.Reset(200 * time.Millisecond)
|
timer.Reset(200 * time.Millisecond)
|
||||||
|
}
|
||||||
sendResponse = timer.C
|
sendResponse = timer.C
|
||||||
case <-sendResponse:
|
case <-sendResponse:
|
||||||
t.Logf("server sending response")
|
t.Logf("server sending response")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue