@@ -3193,26 +3193,26 @@ func TestTransportResponseHeaderLength(t *testing.T) {
3193
3193
}
3194
3194
}
3195
3195
3196
- func TestTransportEventTrace (t * testing.T ) { testTransportEventTrace (t , false ) }
3196
+ func TestTransportEventTrace (t * testing.T ) { testTransportEventTrace (t , h1Mode , false ) }
3197
+ func TestTransportEventTrace_h2 (t * testing.T ) { testTransportEventTrace (t , h2Mode , false ) }
3197
3198
3198
3199
// test a non-nil httptrace.ClientTrace but with all hooks set to zero.
3199
- func TestTransportEventTrace_NoHooks (t * testing.T ) { testTransportEventTrace (t , true ) }
3200
+ func TestTransportEventTrace_NoHooks (t * testing.T ) { testTransportEventTrace (t , h1Mode , true ) }
3201
+ func TestTransportEventTrace_NoHooks_h2 (t * testing.T ) { testTransportEventTrace (t , h2Mode , true ) }
3200
3202
3201
- func testTransportEventTrace (t * testing.T , noHooks bool ) {
3203
+ func testTransportEventTrace (t * testing.T , h2 bool , noHooks bool ) {
3202
3204
defer afterTest (t )
3203
3205
const resBody = "some body"
3204
- ts := httptest . NewServer ( HandlerFunc (func (w ResponseWriter , r * Request ) {
3206
+ cst := newClientServerTest ( t , h2 , HandlerFunc (func (w ResponseWriter , r * Request ) {
3205
3207
if _ , err := ioutil .ReadAll (r .Body ); err != nil {
3206
3208
t .Error (err )
3207
3209
}
3208
3210
io .WriteString (w , resBody )
3209
3211
}))
3210
- defer ts . Close ()
3211
- tr := & Transport {
3212
- ExpectContinueTimeout : 1 * time .Second ,
3212
+ defer cst . close ()
3213
+ if ! h2 {
3214
+ cst . tr . ExpectContinueTimeout = 1 * time .Second
3213
3215
}
3214
- defer tr .CloseIdleConnections ()
3215
- c := & Client {Transport : tr }
3216
3216
3217
3217
var mu sync.Mutex
3218
3218
var buf bytes.Buffer
@@ -3223,7 +3223,8 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
3223
3223
buf .WriteByte ('\n' )
3224
3224
}
3225
3225
3226
- ip , port , err := net .SplitHostPort (ts .Listener .Addr ().String ())
3226
+ addrStr := cst .ts .Listener .Addr ().String ()
3227
+ ip , port , err := net .SplitHostPort (addrStr )
3227
3228
if err != nil {
3228
3229
t .Fatal (err )
3229
3230
}
@@ -3237,7 +3238,7 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
3237
3238
return []net.IPAddr {{IP : net .ParseIP (ip )}}, nil
3238
3239
})
3239
3240
3240
- req , _ := NewRequest ("POST" , "http ://dns-is-faked.golang:"+ port , strings .NewReader ("some body" ))
3241
+ req , _ := NewRequest ("POST" , cst . scheme () + " ://dns-is-faked.golang:"+ port , strings .NewReader ("some body" ))
3241
3242
trace := & httptrace.ClientTrace {
3242
3243
GetConn : func (hostPort string ) { logf ("Getting conn for %v ..." , hostPort ) },
3243
3244
GotConn : func (ci httptrace.GotConnInfo ) { logf ("got conn: %+v" , ci ) },
@@ -3263,7 +3264,7 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
3263
3264
req = req .WithContext (httptrace .WithClientTrace (ctx , trace ))
3264
3265
3265
3266
req .Header .Set ("Expect" , "100-continue" )
3266
- res , err := c .Do (req )
3267
+ res , err := cst . c .Do (req )
3267
3268
if err != nil {
3268
3269
t .Fatal (err )
3269
3270
}
@@ -3292,14 +3293,17 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
3292
3293
wantSub ("Getting conn for dns-is-faked.golang:" + port )
3293
3294
wantSub ("DNS start: {Host:dns-is-faked.golang}" )
3294
3295
wantSub ("DNS done: {Addrs:[{IP:" + ip + " Zone:}] Err:<nil> Coalesced:false}" )
3295
- wantSub ("Connecting to tcp " + ts . Listener . Addr (). String () )
3296
- wantSub ("connected to tcp " + ts . Listener . Addr (). String () + " = <nil>" )
3296
+ wantSub ("Connecting to tcp " + addrStr )
3297
+ wantSub ("connected to tcp " + addrStr + " = <nil>" )
3297
3298
wantSub ("Reused:false WasIdle:false IdleTime:0s" )
3298
3299
wantSub ("first response byte" )
3299
- wantSub ("PutIdleConn = <nil>" )
3300
+ if ! h2 {
3301
+ wantSub ("PutIdleConn = <nil>" )
3302
+ // TODO: implement these next two for Issue 13851
3303
+ wantSub ("Wait100Continue" )
3304
+ wantSub ("Got100Continue" )
3305
+ }
3300
3306
wantSub ("WroteRequest: {Err:<nil>}" )
3301
- wantSub ("Wait100Continue" )
3302
- wantSub ("Got100Continue" )
3303
3307
if strings .Contains (got , " to udp " ) {
3304
3308
t .Errorf ("should not see UDP (DNS) connections" )
3305
3309
}
0 commit comments