Skip to content

Commit a9d7b68

Browse files
committed
add TestConfigureTransportWithOptions
Signed-off-by: duyanghao <[email protected]>
1 parent 664141a commit a9d7b68

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

http2/transport_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"sync/atomic"
3333
"testing"
3434
"time"
35+
"unsafe"
3536

3637
"golang.org/x/net/http2/hpack"
3738
)
@@ -594,6 +595,26 @@ func TestTransportDialTLS(t *testing.T) {
594595
}
595596
}
596597

598+
func TestConfigureTransportWithOptions(t *testing.T) {
599+
t1 := &http.Transport{}
600+
err := ConfigureTransport(t1, WithReadIdleTimeout(10*time.Second), WithPingTimeout(2*time.Second))
601+
if err != nil {
602+
t.Fatal(err)
603+
}
604+
rf := reflect.ValueOf(t1).Elem().FieldByName("altProto")
605+
rf = reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem()
606+
v := rf.Interface().(atomic.Value)
607+
altProto := v.Load().(map[string]http.RoundTripper)
608+
rt := (altProto["https"]).(noDialH2RoundTripper)
609+
t2 := rt.Transport
610+
if t2.ReadIdleTimeout != 10*time.Second {
611+
t.Errorf("expected ReadIdleTimeout to be 10s, got %v", t2.ReadIdleTimeout)
612+
}
613+
if t2.PingTimeout != 2*time.Second {
614+
t.Errorf("expected PingTimeout to be 2s, got %v", t2.PingTimeout)
615+
}
616+
}
617+
597618
func TestConfigureTransport(t *testing.T) {
598619
t1 := &http.Transport{}
599620
err := ConfigureTransport(t1, WithReadIdleTimeout(3*time.Second), WithPingTimeout(1*time.Second))

0 commit comments

Comments
 (0)