diff options
Diffstat (limited to 'libgo/go/net/http/export_test.go')
-rw-r--r-- | libgo/go/net/http/export_test.go | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/libgo/go/net/http/export_test.go b/libgo/go/net/http/export_test.go index 22b7f27968..87b6c0773a 100644 --- a/libgo/go/net/http/export_test.go +++ b/libgo/go/net/http/export_test.go @@ -9,6 +9,7 @@ package http import ( "net" + "net/url" "time" ) @@ -21,7 +22,7 @@ var ExportAppendTime = appendTime func (t *Transport) NumPendingRequestsForTesting() int { t.reqMu.Lock() defer t.reqMu.Unlock() - return len(t.reqConn) + return len(t.reqCanceler) } func (t *Transport) IdleConnKeysForTesting() (keys []string) { @@ -32,7 +33,7 @@ func (t *Transport) IdleConnKeysForTesting() (keys []string) { return } for key := range t.idleConn { - keys = append(keys, key) + keys = append(keys, key.String()) } return } @@ -43,11 +44,12 @@ func (t *Transport) IdleConnCountForTesting(cacheKey string) int { if t.idleConn == nil { return 0 } - conns, ok := t.idleConn[cacheKey] - if !ok { - return 0 + for k, conns := range t.idleConn { + if k.String() == cacheKey { + return len(conns) + } } - return len(conns) + return 0 } func (t *Transport) IdleConnChMapSizeForTesting() int { @@ -56,6 +58,26 @@ func (t *Transport) IdleConnChMapSizeForTesting() int { return len(t.idleConnCh) } +func (t *Transport) IsIdleForTesting() bool { + t.idleMu.Lock() + defer t.idleMu.Unlock() + return t.wantIdle +} + +func (t *Transport) RequestIdleConnChForTesting() { + t.getIdleConnCh(connectMethod{nil, "http", "example.com"}) +} + +func (t *Transport) PutIdleTestConn() bool { + c, _ := net.Pipe() + return t.putIdleConn(&persistConn{ + t: t, + conn: c, // dummy + closech: make(chan struct{}), // so it can be closed + cacheKey: connectMethodKey{"", "http", "example.com"}, + }) +} + func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler { f := func() <-chan time.Time { return ch @@ -63,4 +85,24 @@ func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler { return &timeoutHandler{handler, f, ""} } +func ResetCachedEnvironment() { + httpProxyEnv.reset() + httpsProxyEnv.reset() + noProxyEnv.reset() +} + var DefaultUserAgent = defaultUserAgent + +func ExportRefererForURL(lastReq, newReq *url.URL) string { + return refererForURL(lastReq, newReq) +} + +// SetPendingDialHooks sets the hooks that run before and after handling +// pending dials. +func SetPendingDialHooks(before, after func()) { + prePendingDial, postPendingDial = before, after +} + +var ExportServerNewConn = (*Server).newConn + +var ExportCloseWriteAndWait = (*conn).closeWriteAndWait |