Skip to content

Commit 311ea06

Browse files
committed
add basic test for quic
1 parent 9dda4c3 commit 311ea06

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

transport/internet/splithttp/splithttp_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/xtls/xray-core/common/net"
1515
"github.com/xtls/xray-core/common/protocol/tls/cert"
1616
"github.com/xtls/xray-core/testing/servers/tcp"
17+
"github.com/xtls/xray-core/testing/servers/udp"
1718
"github.com/xtls/xray-core/transport/internet"
1819
. "github.com/xtls/xray-core/transport/internet/splithttp"
1920
"github.com/xtls/xray-core/transport/internet/stat"
@@ -204,3 +205,42 @@ func Test_listenSHAndDial_H2C(t *testing.T) {
204205
t.Error("Expected h2 but got:", resp.ProtoMajor)
205206
}
206207
}
208+
209+
func Test_listenSHAndDial_QUIC(t *testing.T) {
210+
if runtime.GOARCH == "arm64" {
211+
return
212+
}
213+
214+
listenPort := udp.PickPort()
215+
216+
start := time.Now()
217+
218+
streamSettings := &internet.MemoryStreamConfig{
219+
ProtocolName: "splithttp",
220+
ProtocolSettings: &Config{
221+
Path: "shs",
222+
},
223+
SecurityType: "tls",
224+
SecuritySettings: &tls.Config{
225+
AllowInsecure: true,
226+
Certificate: []*tls.Certificate{tls.ParseCertificate(cert.MustGenerate(nil, cert.CommonName("localhost")))},
227+
NextProtocol: []string{"h3"},
228+
},
229+
}
230+
listen, err := ListenSH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) {
231+
go func() {
232+
_ = conn.Close()
233+
}()
234+
})
235+
common.Must(err)
236+
defer listen.Close()
237+
238+
conn, err := Dial(context.Background(), net.UDPDestination(net.DomainAddress("localhost"), listenPort), streamSettings)
239+
common.Must(err)
240+
_ = conn.Close()
241+
242+
end := time.Now()
243+
if !end.Before(start.Add(time.Second * 5)) {
244+
t.Error("end: ", end, " start: ", start)
245+
}
246+
}

0 commit comments

Comments
 (0)