diff --git a/ping_test.go b/ping_test.go index 892af28..71e1cf8 100644 --- a/ping_test.go +++ b/ping_test.go @@ -5,6 +5,7 @@ import ( "errors" "net" "runtime/debug" + "sync" "sync/atomic" "testing" "time" @@ -727,12 +728,15 @@ func TestRunBadRead(t *testing.T) { type testPacketConnOK struct { testPacketConn + m sync.Mutex writeDone int32 buf []byte dst net.Addr } func (c *testPacketConnOK) WriteTo(b []byte, dst net.Addr) (int, error) { + c.m.Lock() + defer c.m.Unlock() c.buf = make([]byte, len(b)) c.dst = dst n := copy(c.buf, b) @@ -741,6 +745,8 @@ func (c *testPacketConnOK) WriteTo(b []byte, dst net.Addr) (int, error) { } func (c *testPacketConnOK) ReadFrom(b []byte) (n int, ttl int, src net.Addr, err error) { + c.m.Lock() + defer c.m.Unlock() if atomic.LoadInt32(&c.writeDone) == 0 { return 0, 0, nil, nil }