diff options
author | Matthew Dempsky <mdempsky@google.com> | 2016-02-20 20:33:34 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2016-02-21 20:59:45 +0000 |
commit | 8caf19c46f9d7cc9011d7acdc464768b5fb15d7e (patch) | |
tree | a4e41ffd7d03cc75fa156c9539e8c2f436efc720 /src/net/dnsclient_unix_test.go | |
parent | 8ffe496ae792a1cdc845c1c019323cf6c05fbb32 (diff) | |
download | go-8caf19c46f9d7cc9011d7acdc464768b5fb15d7e.tar.gz go-8caf19c46f9d7cc9011d7acdc464768b5fb15d7e.zip |
net: fix TestUpdateResolvConf after CL 18860
When writing a fake dnsConfig to conf.dnsConfig, set lastChecked to an
hour into the future. This causes dnsclient_unix.go's
tryUpdate("/etc/resolv.conf") calls to short-circuit and ignore that
/etc/resolv.conf's mtime differs from the test's fake resolv.conf
file. We only need to zero out lastChecked in teardown.
While here, this makes two other tryUpdate(conf.path) test calls
pointless, since they'll now short circuit too.
Fixes #14437.
Change-Id: Ieb520388e319b9826dfa49f134907f4927608a53
Reviewed-on: https://go-review.googlesource.com/19777
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Diffstat (limited to 'src/net/dnsclient_unix_test.go')
-rw-r--r-- | src/net/dnsclient_unix_test.go | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index 934f25b2c9..d7f00c784d 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -124,20 +124,20 @@ func (conf *resolvConfTest) writeAndUpdate(lines []string) error { return err } f.Close() - if err := conf.forceUpdate(conf.path); err != nil { + if err := conf.forceUpdate(conf.path, time.Now().Add(time.Hour)); err != nil { return err } return nil } -func (conf *resolvConfTest) forceUpdate(name string) error { +func (conf *resolvConfTest) forceUpdate(name string, lastChecked time.Time) error { dnsConf := dnsReadConfig(name) conf.mu.Lock() conf.dnsConfig = dnsConf conf.mu.Unlock() for i := 0; i < 5; i++ { if conf.tryAcquireSema() { - conf.lastChecked = time.Time{} + conf.lastChecked = lastChecked conf.releaseSema() return nil } @@ -153,7 +153,7 @@ func (conf *resolvConfTest) servers() []string { } func (conf *resolvConfTest) teardown() error { - err := conf.forceUpdate("/etc/resolv.conf") + err := conf.forceUpdate("/etc/resolv.conf", time.Time{}) os.RemoveAll(conf.dir) return err } @@ -353,7 +353,6 @@ func TestGoLookupIPWithResolverConfig(t *testing.T) { t.Error(err) continue } - conf.tryUpdate(conf.path) addrs, err := goLookupIP(tt.name) if err != nil { if err, ok := err.(*DNSError); !ok || (err.Name != tt.error.(*DNSError).Name || err.Server != tt.error.(*DNSError).Server || err.IsTimeout != tt.error.(*DNSError).IsTimeout) { @@ -392,7 +391,6 @@ func TestGoLookupIPOrderFallbackToFile(t *testing.T) { if err := conf.writeAndUpdate([]string{}); err != nil { t.Fatal(err) } - conf.tryUpdate(conf.path) // Redirect host file lookups. defer func(orig string) { testHookHostsPath = orig }(testHookHostsPath) testHookHostsPath = "testdata/hosts" |