Skip to content

Commit eac155a

Browse files
authored
test(cli): fix TestServer flake due to DNS lookup (#10390)
1 parent 7732ac4 commit eac155a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cli/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,14 @@ func WriteConfigMW(cfg *codersdk.DeploymentValues) clibase.MiddlewareFunc {
12061206
// isLocalURL returns true if the hostname of the provided URL appears to
12071207
// resolve to a loopback address.
12081208
func IsLocalURL(ctx context.Context, u *url.URL) (bool, error) {
1209+
// In tests, we commonly use "example.com" or "google.com", which
1210+
// are not loopback, so avoid the DNS lookup to avoid flakes.
1211+
if flag.Lookup("test.v") != nil {
1212+
if u.Hostname() == "example.com" || u.Hostname() == "google.com" {
1213+
return false, nil
1214+
}
1215+
}
1216+
12091217
resolver := &net.Resolver{}
12101218
ips, err := resolver.LookupIPAddr(ctx, u.Hostname())
12111219
if err != nil {

0 commit comments

Comments
 (0)