代码拉取完成,页面将自动刷新
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)
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。