From 8caf19c46f9d7cc9011d7acdc464768b5fb15d7e Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 20 Feb 2016 20:33:34 -0800 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Mikio Hara --- src/net/dnsclient_unix_test.go | 10 ++++------ 1 file 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" -- 2.48.1