mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-01-06 03:46:17 +08:00
提升通过域名查找服务的性能,轻松支持海量域名
This commit is contained in:
@@ -2,7 +2,9 @@ package serverconfigs
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestServerAddressGroup_Protocol(t *testing.T) {
|
||||
@@ -32,3 +34,79 @@ func TestServerAddressGroup_Protocol(t *testing.T) {
|
||||
a.IsTrue(group.Addr() == "/tmp/my.sock")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerAddressGroup_MatchServerName(t *testing.T) {
|
||||
var group = NewServerAddressGroup("")
|
||||
for i := 0; i < 1_000_000; i++ {
|
||||
group.Add(&ServerConfig{
|
||||
ServerNames: []*ServerNameConfig{
|
||||
{
|
||||
Name: "hello" + types.String(i) + ".com",
|
||||
SubNames: []string{},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
group.Add(&ServerConfig{
|
||||
ServerNames: []*ServerNameConfig{
|
||||
{
|
||||
Name: "hello.com",
|
||||
SubNames: []string{},
|
||||
},
|
||||
},
|
||||
})
|
||||
group.Add(&ServerConfig{
|
||||
ServerNames: []*ServerNameConfig{
|
||||
{
|
||||
Name: "*.hello.com",
|
||||
SubNames: []string{},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
var before = time.Now()
|
||||
defer func() {
|
||||
t.Log(time.Since(before).Seconds()*1000, "ms")
|
||||
}()
|
||||
|
||||
t.Log(group.MatchServerName("hello99999.com").AllStrictNames())
|
||||
t.Log(group.MatchServerName("hello.com").AllStrictNames())
|
||||
t.Log(group.MatchServerName("world.hello.com").AllFuzzyNames())
|
||||
for i := 0; i < 100_000; i++ {
|
||||
_ = group.MatchServerName("world.hello.com")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerAddressGroup_MatchServerCNAME(t *testing.T) {
|
||||
var group = NewServerAddressGroup("")
|
||||
group.Add(&ServerConfig{
|
||||
ServerNames: []*ServerNameConfig{
|
||||
{
|
||||
Name: "hello.com",
|
||||
SubNames: []string{},
|
||||
},
|
||||
},
|
||||
SupportCNAME: true,
|
||||
})
|
||||
group.Add(&ServerConfig{
|
||||
ServerNames: []*ServerNameConfig{
|
||||
{
|
||||
Name: "*.hello.com",
|
||||
SubNames: []string{},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
var before = time.Now()
|
||||
defer func() {
|
||||
t.Log(time.Since(before).Seconds()*1000, "ms")
|
||||
}()
|
||||
|
||||
server := group.MatchServerCNAME("hello.com")
|
||||
if server != nil {
|
||||
t.Log(server.AllStrictNames())
|
||||
} else {
|
||||
t.Log(server)
|
||||
}
|
||||
t.Log(group.MatchServerCNAME("world.hello.com"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user