ping: Add timeout to destinations

This commit is contained in:
世界 2025-08-24 17:46:03 +08:00
parent 8f6cc9f62e
commit 737ebf01c4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 81 additions and 19 deletions

24
ping/destination_test.go Normal file
View 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())
}