Skip to content

Commit b59f11f

Browse files
committed
chore: add singMux inbound test for shadowsocks/trojan/vless/vmess
1 parent 30d90d4 commit b59f11f

File tree

7 files changed

+63
-1
lines changed

7 files changed

+63
-1
lines changed

listener/inbound/mux_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package inbound_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/metacubex/mihomo/adapter/outbound"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
var singMuxProtocolList = []string{"h2mux", "smux"} // don't test "yamux" because it has some confused bugs
12+
13+
// notCloseProxyAdapter is a proxy adapter that does not close the underlying outbound.ProxyAdapter.
14+
// The outbound.SingMux will close the underlying outbound.ProxyAdapter when it is closed, but we don't want to close it.
15+
// The underlying outbound.ProxyAdapter should only be closed by the caller of testSingMux.
16+
type notCloseProxyAdapter struct {
17+
outbound.ProxyAdapter
18+
}
19+
20+
func (n *notCloseProxyAdapter) Close() error {
21+
return nil
22+
}
23+
24+
func testSingMux(t *testing.T, tunnel *TestTunnel, out outbound.ProxyAdapter) {
25+
t.Run("singmux", func(t *testing.T) {
26+
for _, protocol := range singMuxProtocolList {
27+
t.Run(protocol, func(t *testing.T) {
28+
t.Parallel()
29+
singMuxOption := outbound.SingMuxOption{
30+
Enabled: true,
31+
Protocol: protocol,
32+
}
33+
out, err := outbound.NewSingMux(singMuxOption, &notCloseProxyAdapter{out})
34+
assert.NoError(t, err)
35+
defer out.Close()
36+
37+
tunnel.DoTest(t, out)
38+
})
39+
}
40+
})
41+
}

listener/inbound/shadowsocks_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func testInboundShadowSocks0(t *testing.T, inboundOptions inbound.ShadowSocksOpt
7777
defer out.Close()
7878

7979
tunnel.DoTest(t, out)
80+
81+
testSingMux(t, tunnel, out)
8082
}
8183

8284
func TestInboundShadowSocks_Basic(t *testing.T) {

listener/inbound/trojan_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func testInboundTrojan(t *testing.T, inboundOptions inbound.TrojanOption, outbou
4242
defer out.Close()
4343

4444
tunnel.DoTest(t, out)
45+
46+
testSingMux(t, tunnel, out)
4547
}
4648

4749
func TestInboundTrojan_TLS(t *testing.T) {

listener/inbound/vless_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func testInboundVless(t *testing.T, inboundOptions inbound.VlessOption, outbound
4242
defer out.Close()
4343

4444
tunnel.DoTest(t, out)
45+
46+
testSingMux(t, tunnel, out)
4547
}
4648

4749
func TestInboundVless_TLS(t *testing.T) {

listener/inbound/vmess_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func testInboundVMess(t *testing.T, inboundOptions inbound.VmessOption, outbound
4444
defer out.Close()
4545

4646
tunnel.DoTest(t, out)
47+
48+
testSingMux(t, tunnel, out)
4749
}
4850

4951
func TestInboundVMess_Basic(t *testing.T) {

listener/sing/sing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func NewListenerHandler(lc ListenerConfig) (h *ListenerHandler, err error) {
7272
NewStreamContext: func(ctx context.Context, conn net.Conn) context.Context {
7373
return ctx
7474
},
75-
Logger: log.SingLogger,
75+
Logger: log.SingInfoToDebugLogger, // convert sing-mux info log to debug
7676
Handler: h,
7777
Padding: lc.MuxOption.Padding,
7878
Brutal: mux.BrutalOptions{

log/sing.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,17 @@ func (l singLogger) Panic(args ...any) {
6565
Fatalln(fmt.Sprint(args...))
6666
}
6767

68+
type singInfoToDebugLogger struct {
69+
singLogger
70+
}
71+
72+
func (l singInfoToDebugLogger) InfoContext(ctx context.Context, args ...any) {
73+
Debugln(fmt.Sprint(args...))
74+
}
75+
76+
func (l singInfoToDebugLogger) Info(args ...any) {
77+
Debugln(fmt.Sprint(args...))
78+
}
79+
6880
var SingLogger L.ContextLogger = singLogger{}
81+
var SingInfoToDebugLogger L.ContextLogger = singInfoToDebugLogger{}

0 commit comments

Comments
 (0)