]> Cypherpunks repositories - gostls13.git/commitdiff
net: fix TestUpdateResolvConf after CL 18860
authorMatthew Dempsky <mdempsky@google.com>
Sun, 21 Feb 2016 04:33:34 +0000 (20:33 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 21 Feb 2016 20:59:45 +0000 (20:59 +0000)
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>
src/net/dnsclient_unix_test.go

index 934f25b2c94e930b6fd40ecdbc3274fa7c06f1d6..d7f00c784d55ccefd725ccbf38877c0235a2a184 100644 (file)
@@ -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"