ping: Add timeout to destinations
This commit is contained in:
parent
8f6cc9f62e
commit
737ebf01c4
6 changed files with 81 additions and 19 deletions
24
ping/destination_test.go
Normal file
24
ping/destination_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package ping_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/netip"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-tun/ping"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIsClosed(t *testing.T) {
|
||||
t.Parallel()
|
||||
destination, err := ping.ConnectDestination(context.Background(), logger.NOP(), nil, netip.MustParseAddr("1.1.1.1"), nil, 30*time.Second)
|
||||
require.NoError(t, err)
|
||||
defer destination.Close()
|
||||
time.Sleep(1 * time.Second)
|
||||
require.False(t, destination.IsClosed())
|
||||
destination.Close()
|
||||
require.True(t, destination.IsClosed())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue