windivert: stabilize Windows driver lifecycle

This commit is contained in:
世界
2026-07-14 12:31:01 +08:00
parent a800468aa3
commit 04e60002eb
5 changed files with 273 additions and 183 deletions
@@ -5,13 +5,29 @@ package tlsspoof
import (
"encoding/hex"
"io"
"log"
"net"
"os"
"testing"
"time"
"github.com/sagernet/sing-box/internal/winmutex"
E "github.com/sagernet/sing/common/exceptions"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
exitCode, err := winmutex.WithLock("SingBoxWinDivertIntegrationTests", 3*time.Minute, func() (int, error) {
return m.Run(), nil
})
if err != nil {
log.Print(E.Cause(err, "run in exclusive WinDivert integration test environment"))
os.Exit(1)
}
os.Exit(exitCode)
}
func newSpoofer(t *testing.T, conn net.Conn, method Method) rawSpoofer {
t.Helper()
s, err := newRawSpoofer(conn, method)