mirror of
https://github.com/golang/go.git
synced 2025-11-01 09:10:57 +00:00
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>
This commit is contained in:
parent
8ffe496ae7
commit
8caf19c46f
1 changed files with 4 additions and 6 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue