defer conf.teardown()
for _, tt := range tests {
- if !conf.forceUpdateConf(tt.resolv, time.Now().Add(time.Hour)) {
+ if !conf.forceUpdateConf(tt.resolv, distantFuture) {
t.Errorf("%s: failed to change resolv config", tt.name)
}
for _, ht := range tt.hostTests {
conf.ch = make(chan struct{}, 1)
}
+// distantFuture is a sentinel time used for tests to signal that
+// resolv.conf should not be rechecked.
+var distantFuture = time.Date(3000, 1, 2, 3, 4, 5, 6, time.UTC)
+
// tryUpdate tries to update conf with the named resolv.conf file.
// The name variable only exists for testing. It is otherwise always
// "/etc/resolv.conf".
func (conf *resolverConfig) tryUpdate(name string) {
conf.initOnce.Do(conf.init)
- if conf.dnsConfig.Load().noReload {
+ dc := conf.dnsConfig.Load()
+ if dc.noReload {
return
}
defer conf.releaseSema()
now := time.Now()
- if conf.lastChecked.After(now.Add(-5 * time.Second)) {
+ if (len(dc.servers) > 0 && conf.lastChecked.After(now.Add(-5*time.Second))) ||
+ conf.lastChecked == distantFuture {
return
}
conf.lastChecked = now