fix stats test race (#1560)

* fix stats test race
* and try fix TestMapAddressEnv race
This commit is contained in:
Menghan Li
2017-10-04 14:30:12 -07:00
committed by GitHub
parent 7103997bd8
commit cf79c84979
2 changed files with 26 additions and 23 deletions

View File

@ -46,29 +46,6 @@ func overwrite(hpfe func(req *http.Request) (*url.URL, error)) func() {
}
}
func TestMapAddressEnv(t *testing.T) {
// Overwrite the function in the test and restore them in defer.
hpfe := func(req *http.Request) (*url.URL, error) {
if req.URL.Host == envTestAddr {
return &url.URL{
Scheme: "https",
Host: envProxyAddr,
}, nil
}
return nil, nil
}
defer overwrite(hpfe)()
// envTestAddr should be handled by ProxyFromEnvironment.
got, err := mapAddress(context.Background(), envTestAddr)
if err != nil {
t.Error(err)
}
if got != envProxyAddr {
t.Errorf("want %v, got %v", envProxyAddr, got)
}
}
type proxyServer struct {
t *testing.T
lis net.Listener
@ -177,3 +154,27 @@ func TestHTTPConnect(t *testing.T) {
t.Fatalf("received msg: %v, want %v", recvBuf, msg)
}
}
func TestMapAddressEnv(t *testing.T) {
defer leakcheck.Check(t)
// Overwrite the function in the test and restore them in defer.
hpfe := func(req *http.Request) (*url.URL, error) {
if req.URL.Host == envTestAddr {
return &url.URL{
Scheme: "https",
Host: envProxyAddr,
}, nil
}
return nil, nil
}
defer overwrite(hpfe)()
// envTestAddr should be handled by ProxyFromEnvironment.
got, err := mapAddress(context.Background(), envTestAddr)
if err != nil {
t.Error(err)
}
if got != envProxyAddr {
t.Errorf("want %v, got %v", envProxyAddr, got)
}
}