24 lines
752 B
Go
24 lines
752 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
// TestTransportPool:连接池调优参数必须落在 client 实际使用的 transport 上,
|
|
// 而不是一个从未被引用的变量(否则调优静默失效)。
|
|
func TestTransportPool(t *testing.T) {
|
|
c := NewAPIClient("http://127.0.0.1:1")
|
|
tr := c.Transport()
|
|
if tr == nil {
|
|
t.Fatal("client.Transport 为 nil:连接池配置根本没有被引用")
|
|
}
|
|
if tr.MaxIdleConnsPerHost < 1000 {
|
|
t.Fatalf("MaxIdleConnsPerHost = %d,期望 >= 1000(调优未生效)",
|
|
tr.MaxIdleConnsPerHost)
|
|
}
|
|
if tr.MaxConnsPerHost < 1000 {
|
|
t.Fatalf("MaxConnsPerHost = %d,期望 >= 1000", tr.MaxConnsPerHost)
|
|
}
|
|
if tr.MaxIdleConns < 1000 {
|
|
t.Fatalf("MaxIdleConns = %d,期望 >= 1000", tr.MaxIdleConns)
|
|
}
|
|
}
|