github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/net/http/export_test.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Bridge package to expose http internals to tests in the http_test 6 // package. 7 8 package http 9 10 import ( 11 "net" 12 "time" 13 ) 14 15 func NewLoggingConn(baseName string, c net.Conn) net.Conn { 16 return newLoggingConn(baseName, c) 17 } 18 19 func (t *Transport) NumPendingRequestsForTesting() int { 20 t.reqMu.Lock() 21 defer t.reqMu.Unlock() 22 return len(t.reqConn) 23 } 24 25 func (t *Transport) IdleConnKeysForTesting() (keys []string) { 26 keys = make([]string, 0) 27 t.idleMu.Lock() 28 defer t.idleMu.Unlock() 29 if t.idleConn == nil { 30 return 31 } 32 for key := range t.idleConn { 33 keys = append(keys, key) 34 } 35 return 36 } 37 38 func (t *Transport) IdleConnCountForTesting(cacheKey string) int { 39 t.idleMu.Lock() 40 defer t.idleMu.Unlock() 41 if t.idleConn == nil { 42 return 0 43 } 44 conns, ok := t.idleConn[cacheKey] 45 if !ok { 46 return 0 47 } 48 return len(conns) 49 } 50 51 func NewTestTimeoutHandler(handler Handler, ch <-chan time.Time) Handler { 52 f := func() <-chan time.Time { 53 return ch 54 } 55 return &timeoutHandler{handler, f, ""} 56 } 57 58 var DefaultUserAgent = defaultUserAgent