Skip to content

Commit f7e03d0

Browse files
authored
fix: client test race (#149)
1 parent dcb0b5a commit f7e03d0

File tree

4 files changed

+22
-53
lines changed

4 files changed

+22
-53
lines changed

pkg/app/client/client_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ func TestClientReadTimeout(t *testing.T) {
392392
ReadTimeout: time.Second * 4,
393393
MaxIdempotentCallAttempts: 1,
394394
Dialer: standard.NewDialer(),
395-
Addr: opt.Addr,
396395
},
396+
Addr: opt.Addr,
397397
}
398398

399399
req := protocol.AcquireRequest()
@@ -689,9 +689,9 @@ func TestHostClientPendingRequests(t *testing.T) {
689689

690690
c := &http1.HostClient{
691691
ClientOptions: &http1.ClientOptions{
692-
Addr: "foobar",
693692
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
694693
},
694+
Addr: "foobar",
695695
}
696696

697697
pendingRequests := c.PendingRequests()
@@ -780,10 +780,10 @@ func TestHostClientMaxConnsWithDeadline(t *testing.T) {
780780

781781
c := &http1.HostClient{
782782
ClientOptions: &http1.ClientOptions{
783-
Addr: "foobar",
784783
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
785784
MaxConns: 1,
786785
},
786+
Addr: "foobar",
787787
}
788788

789789
for i := 0; i < 5; i++ {
@@ -849,10 +849,10 @@ func TestHostClientMaxConnDuration(t *testing.T) {
849849

850850
c := &http1.HostClient{
851851
ClientOptions: &http1.ClientOptions{
852-
Addr: "foobar",
853852
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
854853
MaxConnDuration: 10 * time.Millisecond,
855854
},
855+
Addr: "foobar",
856856
}
857857

858858
for i := 0; i < 5; i++ {
@@ -895,11 +895,11 @@ func TestHostClientMultipleAddrs(t *testing.T) {
895895
dialsCount := make(map[string]int)
896896
c := &http1.HostClient{
897897
ClientOptions: &http1.ClientOptions{
898-
Addr: "foo,bar,baz",
899898
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, 1*time.Second, func(network, addr string, timeout time.Duration, tlsConfig *tls.Config) {
900899
dialsCount[addr]++
901900
}),
902901
},
902+
Addr: "foo,bar,baz",
903903
}
904904

905905
for i := 0; i < 9; i++ {
@@ -961,9 +961,9 @@ func TestClientFollowRedirects(t *testing.T) {
961961

962962
c := &http1.HostClient{
963963
ClientOptions: &http1.ClientOptions{
964-
Addr: "xxx",
965964
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, 1*time.Second, nil),
966965
},
966+
Addr: "xxx",
967967
}
968968

969969
for i := 0; i < 10; i++ {
@@ -1055,11 +1055,11 @@ func TestHostClientMaxConnWaitTimeoutSuccess(t *testing.T) {
10551055

10561056
c := &http1.HostClient{
10571057
ClientOptions: &http1.ClientOptions{
1058-
Addr: "foobar",
10591058
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
10601059
MaxConns: 1,
10611060
MaxConnWaitTimeout: 200 * time.Millisecond,
10621061
},
1062+
Addr: "foobar",
10631063
}
10641064

10651065
for i := 0; i < 5; i++ {
@@ -1124,11 +1124,11 @@ func TestHostClientMaxConnWaitTimeoutError(t *testing.T) {
11241124

11251125
c := &http1.HostClient{
11261126
ClientOptions: &http1.ClientOptions{
1127-
Addr: "foobar",
11281127
Dialer: newMockDialerWithCustomFunc(opt.Network, opt.Addr, time.Second, nil),
11291128
MaxConns: 1,
11301129
MaxConnWaitTimeout: 10 * time.Millisecond,
11311130
},
1131+
Addr: "foobar",
11321132
}
11331133

11341134
var errNoFreeConnsCount uint32

pkg/protocol/client/client.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ package client
4343

4444
import (
4545
"context"
46-
"crypto/tls"
4746
"sync"
4847
"time"
4948

@@ -79,34 +78,6 @@ type Doer interface {
7978
Do(ctx context.Context, req *protocol.Request, resp *protocol.Response) error
8079
}
8180

82-
type HostClientConfig struct {
83-
DynamicConfig
84-
85-
Name string
86-
87-
NoDefaultUserAgentHeader bool
88-
DialDualStack bool
89-
DisableHeaderNamesNormalizing bool
90-
DisablePathNormalizing bool
91-
IsTLS bool
92-
93-
TLSConfig *tls.Config
94-
95-
MaxConns int
96-
MaxIdempotentCallAttempts int
97-
MaxResponseBodySize int
98-
99-
RetryIf RetryIfFunc
100-
ResponseBodyStream bool
101-
102-
DialTimeout time.Duration
103-
MaxIdleConnDuration time.Duration
104-
MaxConnDuration time.Duration
105-
ReadTimeout time.Duration
106-
WriteTimeout time.Duration
107-
MaxConnWaitTimeout time.Duration
108-
}
109-
11081
// DynamicConfig is config set which will be confirmed when starts a request.
11182
type DynamicConfig struct {
11283
Addr string

pkg/protocol/http1/client.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ type HostClient struct {
9090

9191
*ClientOptions
9292

93+
// Comma-separated list of upstream HTTP server host addresses,
94+
// which are passed to Dialer in a round-robin manner.
95+
//
96+
// Each address may contain port if default dialer is used.
97+
// For example,
98+
//
99+
// - foobar.com:80
100+
// - foobar.com:443
101+
// - foobar.com:8080
102+
Addr string
103+
IsTLS bool
104+
ProxyURI *protocol.URI
105+
93106
clientName atomic.Value
94107
lastUseTime uint32
95108

@@ -1044,17 +1057,6 @@ func NewHostClient(c *ClientOptions) client.HostClient {
10441057
}
10451058

10461059
type ClientOptions struct {
1047-
// Comma-separated list of upstream HTTP server host addresses,
1048-
// which are passed to Dialer in a round-robin manner.
1049-
//
1050-
// Each address may contain port if default dialer is used.
1051-
// For example,
1052-
//
1053-
// - foobar.com:80
1054-
// - foobar.com:443
1055-
// - foobar.com:8080
1056-
Addr string
1057-
10581060
// Client name. Used in User-Agent request header.
10591061
Name string
10601062

@@ -1086,8 +1088,6 @@ type ClientOptions struct {
10861088
// Optional TLS config.
10871089
TLSConfig *tls.Config
10881090

1089-
IsTLS bool
1090-
10911091
// Maximum number of connections which may be established to all hosts
10921092
// listed in Addr.
10931093
//
@@ -1168,6 +1168,4 @@ type ClientOptions struct {
11681168

11691169
// ResponseBodyStream enables response body streaming
11701170
ResponseBodyStream bool
1171-
1172-
ProxyURI *protocol.URI
11731171
}

pkg/protocol/http1/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ func TestHostClientMaxConnWaitTimeoutWithEarlierDeadline(t *testing.T) {
7474

7575
c := &HostClient{
7676
ClientOptions: &ClientOptions{
77-
Addr: "foobar",
7877
Dialer: newSlowConnDialer(func(network, addr string) (network.Conn, error) {
7978
return mock.SlowReadDialer(addr)
8079
}),
8180
MaxConns: 1,
8281
MaxConnWaitTimeout: 50 * time.Millisecond,
8382
},
83+
Addr: "foobar",
8484
}
8585

8686
var errTimeoutCount uint32

0 commit comments

Comments
 (0)