1 Star 0 Fork 0

jinyule/cow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
conn_pool_test.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"testing"
"time"
)
func TestGetFromEmptyPool(t *testing.T) {
// should not block
sv := connPool.Get("foo", true)
if sv != nil {
t.Error("get non nil server conn from empty conn pool")
}
}
func TestConnPool(t *testing.T) {
closeOn := time.Now().Add(10 * time.Second)
conns := []*serverConn{
{hostPort: "example.com:80", willCloseOn: closeOn},
{hostPort: "example.com:80", willCloseOn: closeOn},
{hostPort: "example.com:80", willCloseOn: closeOn},
{hostPort: "example.com:443", willCloseOn: closeOn},
{hostPort: "google.com:443", willCloseOn: closeOn},
{hostPort: "google.com:443", willCloseOn: closeOn},
{hostPort: "www.google.com:80", willCloseOn: closeOn},
}
for _, sv := range conns {
connPool.Put(sv)
}
testData := []struct {
hostPort string
found bool
}{
{"example.com", false},
{"example.com:80", true},
{"example.com:80", true},
{"example.com:80", true},
{"example.com:80", false}, // has 3 such conn
{"www.google.com:80", true},
}
for _, td := range testData {
sv := connPool.Get(td.hostPort, true)
if td.found {
if sv == nil {
t.Error("should find conn for", td.hostPort)
} else if sv.hostPort != td.hostPort {
t.Errorf("hostPort should be: %s, got: %s\n", td.hostPort, sv.hostPort)
}
} else if sv != nil {
t.Errorf("should NOT find conn for %s, got conn for: %s\n",
td.hostPort, sv.hostPort)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jinyule/cow.git
git@gitee.com:jinyule/cow.git
jinyule
cow
cow
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385