From 45587c524ea3e101761329c8e07bdc84f279f264 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Fri, 27 Mar 2026 11:12:32 +0800 Subject: [PATCH] chore: adjust sing-mux test --- .github/workflows/build.yml | 1 + listener/inbound/common_test.go | 14 +++++++------- listener/inbound/mux_test.go | 9 +++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b8c1671e..143bb6d21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -316,6 +316,7 @@ jobs: - name: Test if: ${{ matrix.jobs.test == 'test' }} run: | + export SKIP_CONCURRENT_TEST=1 go test ./... echo "---test with_gvisor---" go test ./... -tags "with_gvisor" -count=1 diff --git a/listener/inbound/common_test.go b/listener/inbound/common_test.go index b1be5e4d5..eabdb6b11 100644 --- a/listener/inbound/common_test.go +++ b/listener/inbound/common_test.go @@ -9,6 +9,7 @@ import ( "io" "net" "net/netip" + "os" "strconv" "sync" "testing" @@ -61,7 +62,6 @@ type TestTunnel struct { HandleUDPPacketFn func(packet C.UDPPacket, metadata *C.Metadata) NatTableFn func() C.NatTable CloseFn func() error - DoTestFn func(t *testing.T, proxy C.ProxyAdapter) DoSequentialTestFn func(t *testing.T, proxy C.ProxyAdapter) DoConcurrentTestFn func(t *testing.T, proxy C.ProxyAdapter) } @@ -83,7 +83,8 @@ func (tt *TestTunnel) Close() error { } func (tt *TestTunnel) DoTest(t *testing.T, proxy C.ProxyAdapter) { - tt.DoTestFn(t, proxy) + tt.DoSequentialTestFn(t, proxy) + tt.DoConcurrentTestFn(t, proxy) } func (tt *TestTunnel) DoSequentialTest(t *testing.T, proxy C.ProxyAdapter) { @@ -236,6 +237,9 @@ func NewHttpTestTunnel() *TestTunnel { concurrentTestFn := func(t *testing.T, proxy C.ProxyAdapter) { // Concurrent testing to detect stress t.Run("Concurrent", func(t *testing.T) { + if skip, _ := strconv.ParseBool(os.Getenv("SKIP_CONCURRENT_TEST")); skip { + t.Skip("skip concurrent test") + } wg := sync.WaitGroup{} num := len(httpData) / 1024 for i := 1; i <= num; i++ { @@ -296,11 +300,7 @@ func NewHttpTestTunnel() *TestTunnel { } <-c.ch }, - CloseFn: ln.Close, - DoTestFn: func(t *testing.T, proxy C.ProxyAdapter) { - sequentialTestFn(t, proxy) - concurrentTestFn(t, proxy) - }, + CloseFn: ln.Close, DoSequentialTestFn: sequentialTestFn, DoConcurrentTestFn: concurrentTestFn, } diff --git a/listener/inbound/mux_test.go b/listener/inbound/mux_test.go index 0f632220e..09facdb87 100644 --- a/listener/inbound/mux_test.go +++ b/listener/inbound/mux_test.go @@ -6,9 +6,11 @@ import ( "github.com/metacubex/mihomo/adapter/outbound" "github.com/stretchr/testify/assert" + "golang.org/x/exp/slices" ) -var singMuxProtocolList = []string{"smux", "yamux"} // don't test "h2mux" because it has some confused bugs +var singMuxProtocolList = []string{"h2mux", "smux", "yamux"} +var singMuxProtocolListLong = []string{"yamux"} // don't test "smux", "h2mux" because it has some confused bugs // notCloseProxyAdapter is a proxy adapter that does not close the underlying outbound.ProxyAdapter. // The outbound.SingMux will close the underlying outbound.ProxyAdapter when it is closed, but we don't want to close it. @@ -37,7 +39,10 @@ func testSingMux(t *testing.T, tunnel *TestTunnel, out outbound.ProxyAdapter) { } defer out.Close() - tunnel.DoTest(t, out) + tunnel.DoSequentialTest(t, out) + if slices.Contains(singMuxProtocolListLong, protocol) { + tunnel.DoConcurrentTest(t, out) + } }) } })