mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-23 01:56:48 +08:00
SplitHTTP client: Add xmux (multiplex controller) for H3 & H2 (#3613)
https://github.com/XTLS/Xray-core/pull/3613#issuecomment-2351954957 Closes https://github.com/XTLS/Xray-core/issues/3560#issuecomment-2247495778 --------- Co-authored-by: mmmray <142015632+mmmray@users.noreply.github.com>
This commit is contained in:
88
transport/internet/splithttp/mux_test.go
Normal file
88
transport/internet/splithttp/mux_test.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package splithttp_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/xtls/xray-core/transport/internet/splithttp"
|
||||
)
|
||||
|
||||
type fakeRoundTripper struct{}
|
||||
|
||||
func TestMaxConnections(t *testing.T) {
|
||||
config := Multiplexing{
|
||||
MaxConnections: &RandRangeConfig{From: 4, To: 4},
|
||||
}
|
||||
|
||||
mux := NewMuxManager(config, func() interface{} {
|
||||
return &fakeRoundTripper{}
|
||||
})
|
||||
|
||||
clients := make(map[interface{}]struct{})
|
||||
for i := 0; i < 8; i++ {
|
||||
clients[mux.GetResource(context.Background())] = struct{}{}
|
||||
}
|
||||
|
||||
if len(clients) != 4 {
|
||||
t.Error("did not get 4 distinct clients, got ", len(clients))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCMaxReuseTimes(t *testing.T) {
|
||||
config := Multiplexing{
|
||||
CMaxReuseTimes: &RandRangeConfig{From: 2, To: 2},
|
||||
}
|
||||
|
||||
mux := NewMuxManager(config, func() interface{} {
|
||||
return &fakeRoundTripper{}
|
||||
})
|
||||
|
||||
clients := make(map[interface{}]struct{})
|
||||
for i := 0; i < 64; i++ {
|
||||
clients[mux.GetResource(context.Background())] = struct{}{}
|
||||
}
|
||||
|
||||
if len(clients) != 32 {
|
||||
t.Error("did not get 32 distinct clients, got ", len(clients))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxConcurrency(t *testing.T) {
|
||||
config := Multiplexing{
|
||||
MaxConcurrency: &RandRangeConfig{From: 2, To: 2},
|
||||
}
|
||||
|
||||
mux := NewMuxManager(config, func() interface{} {
|
||||
return &fakeRoundTripper{}
|
||||
})
|
||||
|
||||
clients := make(map[interface{}]struct{})
|
||||
for i := 0; i < 64; i++ {
|
||||
client := mux.GetResource(context.Background())
|
||||
client.OpenRequests.Add(1)
|
||||
clients[client] = struct{}{}
|
||||
}
|
||||
|
||||
if len(clients) != 32 {
|
||||
t.Error("did not get 32 distinct clients, got ", len(clients))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
config := Multiplexing{}
|
||||
|
||||
mux := NewMuxManager(config, func() interface{} {
|
||||
return &fakeRoundTripper{}
|
||||
})
|
||||
|
||||
clients := make(map[interface{}]struct{})
|
||||
for i := 0; i < 64; i++ {
|
||||
client := mux.GetResource(context.Background())
|
||||
client.OpenRequests.Add(1)
|
||||
clients[client] = struct{}{}
|
||||
}
|
||||
|
||||
if len(clients) != 1 {
|
||||
t.Error("did not get 1 distinct clients, got ", len(clients))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user