Skip to content

Commit

Permalink
Try to fix tests with dial timeouts (#1940)
Browse files Browse the repository at this point in the history
Use github.com and .io instead of example.com and google.com as they are
probably more reliable within Github actions.
  • Loading branch information
erikdubbelboer authored Jan 15, 2025
1 parent 49942c7 commit b1c2788
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
5 changes: 5 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,11 @@ func TestClientConfigureClientFailed(t *testing.T) {
ConfigureClient: func(hc *HostClient) error {
return errors.New("failed to configure")
},
Dial: func(addr string) (net.Conn, error) {
return &singleEchoConn{
b: []byte("HTTP/1.1 345 OK\r\nContent-Type: foobar\r\n\r\n"),
}, nil
},
}

req := Request{}
Expand Down
52 changes: 26 additions & 26 deletions fasthttpproxy/dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestDialer_GetDialFunc(t *testing.T) {
}()
t.Setenv("HTTP_PROXY", "http://127.0.0.1:"+proxyListenPorts[2])
t.Setenv("HTTPS_PROXY", "http://127.0.0.1:"+proxyListenPorts[3])
t.Setenv("NO_PROXY", "example.com")
t.Setenv("NO_PROXY", "github.com")
type fields struct {
httpProxy string
httpsProxy string
Expand All @@ -45,157 +45,157 @@ func TestDialer_GetDialFunc(t *testing.T) {
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{0, 1, 0, 0},
dialAddr: "www.google.com:443",
dialAddr: "github.io:443",
},
{
name: "proxy information comes from the configuration. dial http host",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{1, 0, 0, 0},
dialAddr: "www.google.com:80",
dialAddr: "github.io:80",
},
{
name: "proxy information comes from the configuration. dial http host matched with noProxy",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "example.com:80",
dialAddr: "github.com:80",
},
{
name: "proxy information comes from the configuration. dial https host matched with noProxy",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "example.com:443",
dialAddr: "github.com:443",
},
{
name: "proxy information comes from the env. dial http host",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: true,
},
wantCounts: []int64{0, 0, 1, 0},
dialAddr: "www.google.com:80",
dialAddr: "github.io:80",
},
{
name: "proxy information comes from the env. dial https host",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: true,
},
wantCounts: []int64{0, 0, 0, 1},
dialAddr: "www.google.com:443",
dialAddr: "github.io:443",
},

{
name: "proxy information comes from the env. dial http host matched with noProxy",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: true,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "example.com:80",
dialAddr: "github.com:80",
},
{
name: "proxy information comes from the env. dial https host matched with noProxy",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[1],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: true,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "example.com:443",
dialAddr: "github.com:443",
},
{
name: "proxy information comes from the configuration and httpProxy same with httpsProxy. dial http host",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[0],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{1, 0, 0, 0},
dialAddr: "www.google.com:80",
dialAddr: "github.io:80",
},
{
name: "proxy information comes from the configuration and httpProxy same with httpsProxy. dial https host",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[0],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{1, 0, 0, 0},
dialAddr: "www.google.com:443",
dialAddr: "github.io:443",
},
{
name: "proxy information comes from the configuration and httpProxy same with httpsProxy. dial http host matched with noProxy",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[0],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "example.com:80",
dialAddr: "github.com:80",
},
{
name: "proxy information comes from the configuration and httpProxy same with httpsProxy. dial https host matched with noProxy",
fields: fields{
httpProxy: "http://127.0.0.1:" + proxyListenPorts[0],
httpsProxy: "http://127.0.0.1:" + proxyListenPorts[0],
noProxy: "example.com",
noProxy: "github.com",
},
args: args{
useEnv: false,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "example.com:443",
dialAddr: "github.com:443",
},
{
name: "return an error for unsupported proxy protocols.",
Expand All @@ -207,7 +207,7 @@ func TestDialer_GetDialFunc(t *testing.T) {
useEnv: false,
},
wantCounts: []int64{0, 0, 0, 0},
dialAddr: "www.google.com:80",
dialAddr: "github.io:80",
wantErrMessage: "proxy: unknown scheme: socket6",
},
}
Expand Down

0 comments on commit b1c2788

Please sign in to comment.