mirror of
https://github.com/go-ping/ping.git
synced 2025-08-28 17:42:46 +00:00
Return ctx.Err() from RunWithContext() and Run() (#50)
Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
This commit is contained in:
parent
118abe2a50
commit
343775cbaa
1
ping.go
1
ping.go
@ -498,6 +498,7 @@ func (p *Pinger) run(ctx context.Context, conn packetConn) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
p.Stop()
|
||||
return ctx.Err()
|
||||
case <-p.done:
|
||||
}
|
||||
return nil
|
||||
|
@ -801,7 +801,7 @@ func TestRunWithTimeoutContext(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||
defer cancel()
|
||||
err = pinger.run(ctx, conn)
|
||||
AssertTrue(t, err == nil)
|
||||
AssertTrue(t, errors.Is(err, context.DeadlineExceeded))
|
||||
elapsedTime := time.Since(start)
|
||||
AssertTrue(t, elapsedTime < 10*time.Second)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user