aboutsummaryrefslogtreecommitdiff
path: root/test/cache_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-09-20 11:36:41 +0100
committerGravatar GitHub <noreply@github.com> 2017-09-20 11:36:41 +0100
commitcd5879f866641141a241706d0d0a0219e52b7e68 (patch)
treee88a040834128512a4682aebae5aeafa456588f1 /test/cache_test.go
parentbe4770927048627b59a6ce80587d668d7c028518 (diff)
downloadcoredns-cd5879f866641141a241706d0d0a0219e52b7e68.tar.gz
coredns-cd5879f866641141a241706d0d0a0219e52b7e68.tar.zst
coredns-cd5879f866641141a241706d0d0a0219e52b7e68.zip
plugin/cache: cap TTL on first answer (#1092)
Cache would let the first response through and would then cap subsequent ones to whatever the cache duration was. This would lead to huge drops in TTL values: 3600 -> 20 for instance, which is not only bad, but can mess up your careful TTL planning business. This PR fixes that and applies the cache duration to all replies. As a bonus I could remove a time.Sleep() from the cache test and just check for the cache duration as the TTL on the reply. Fixes #1038
Diffstat (limited to 'test/cache_test.go')
-rw-r--r--test/cache_test.go25
1 files changed, 3 insertions, 22 deletions
diff --git a/test/cache_test.go b/test/cache_test.go
index 2379cd2a3..37aa55368 100644
--- a/test/cache_test.go
+++ b/test/cache_test.go
@@ -1,10 +1,7 @@
package test
import (
- "io/ioutil"
- "log"
"testing"
- "time"
"github.com/coredns/coredns/plugin/proxy"
"github.com/coredns/coredns/plugin/test"
@@ -14,7 +11,6 @@ import (
)
func TestLookupCache(t *testing.T) {
- t.Parallel()
// Start auth. CoreDNS holding the auth zone.
name, rm, err := test.TempFile(".", exampleOrg)
if err != nil {
@@ -35,7 +31,7 @@ func TestLookupCache(t *testing.T) {
// Start caching proxy CoreDNS that we want to test.
corefile = `example.org:0 {
proxy . ` + udp + `
- cache
+ cache 10
}
`
i, udp, _, err = CoreDNSServerAndPorts(corefile)
@@ -44,8 +40,6 @@ func TestLookupCache(t *testing.T) {
}
defer i.Stop()
- log.SetOutput(ioutil.Discard)
-
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
@@ -59,20 +53,7 @@ func TestLookupCache(t *testing.T) {
}
ttl := resp.Answer[0].Header().Ttl
-
- time.Sleep(2 * time.Second) // TODO(miek): meh.
-
- resp, err = p.Lookup(state, "example.org.", dns.TypeA)
- if err != nil {
- t.Fatal("Expected to receive reply, but didn't")
- }
-
- // expect answer section with A record in it
- if len(resp.Answer) == 0 {
- t.Error("Expected to at least one RR in the answer section, got none")
- }
- newTTL := resp.Answer[0].Header().Ttl
- if newTTL >= ttl {
- t.Errorf("Expected TTL to be lower than: %d, got %d", ttl, newTTL)
+ if ttl != 10 { // as set in the Corefile
+ t.Errorf("Expected TTL to be %d, got %d", 10, ttl)
}
}