2018-02-15 10:21:57 +01:00
|
|
|
package forward
|
|
|
|
|
|
|
|
|
|
import (
|
2018-04-22 08:34:35 +01:00
|
|
|
"context"
|
2018-02-15 10:21:57 +01:00
|
|
|
"sync/atomic"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
2023-03-24 12:55:51 +00:00
|
|
|
"github.com/coredns/coredns/plugin/pkg/proxy"
|
2018-09-19 07:29:37 +01:00
|
|
|
"github.com/coredns/coredns/plugin/pkg/transport"
|
2018-02-15 10:21:57 +01:00
|
|
|
"github.com/coredns/coredns/plugin/test"
|
|
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestHealth(t *testing.T) {
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
defaultTimeout = 10 * time.Millisecond
|
|
|
|
|
|
2018-02-15 10:21:57 +01:00
|
|
|
i := uint32(0)
|
2020-03-06 11:52:43 +01:00
|
|
|
q := uint32(0)
|
2018-02-15 10:21:57 +01:00
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
2020-03-06 11:52:43 +01:00
|
|
|
if atomic.LoadUint32(&q) == 0 { //drop the first query to trigger health-checking
|
|
|
|
|
atomic.AddUint32(&q, 1)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if r.Question[0].Name == "." && r.RecursionDesired == true {
|
|
|
|
|
atomic.AddUint32(&i, 1)
|
|
|
|
|
}
|
|
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
|
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealth", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
2020-03-06 11:52:43 +01:00
|
|
|
f := New()
|
|
|
|
|
f.SetProxy(p)
|
|
|
|
|
defer f.OnShutdown()
|
|
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
time.Sleep(20 * time.Millisecond)
|
2020-03-06 11:52:43 +01:00
|
|
|
i1 := atomic.LoadUint32(&i)
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
if i1 != 1 {
|
|
|
|
|
t.Errorf("Expected number of health checks with RecursionDesired==true to be %d, got %d", 1, i1)
|
2020-03-06 11:52:43 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 15:45:52 +01:00
|
|
|
func TestHealthTCP(t *testing.T) {
|
|
|
|
|
defaultTimeout = 10 * time.Millisecond
|
|
|
|
|
|
|
|
|
|
i := uint32(0)
|
|
|
|
|
q := uint32(0)
|
|
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
if atomic.LoadUint32(&q) == 0 { //drop the first query to trigger health-checking
|
|
|
|
|
atomic.AddUint32(&q, 1)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if r.Question[0].Name == "." && r.RecursionDesired == true {
|
|
|
|
|
atomic.AddUint32(&i, 1)
|
|
|
|
|
}
|
|
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
|
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealthTCP", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetTCPTransport()
|
2022-02-09 15:45:52 +01:00
|
|
|
f := New()
|
|
|
|
|
f.SetProxy(p)
|
|
|
|
|
defer f.OnShutdown()
|
|
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{TCP: true}, req)
|
|
|
|
|
|
|
|
|
|
time.Sleep(20 * time.Millisecond)
|
|
|
|
|
i1 := atomic.LoadUint32(&i)
|
|
|
|
|
if i1 != 1 {
|
|
|
|
|
t.Errorf("Expected number of health checks with RecursionDesired==true to be %d, got %d", 1, i1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 11:52:43 +01:00
|
|
|
func TestHealthNoRecursion(t *testing.T) {
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
defaultTimeout = 10 * time.Millisecond
|
|
|
|
|
|
2020-03-06 11:52:43 +01:00
|
|
|
i := uint32(0)
|
|
|
|
|
q := uint32(0)
|
|
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
if atomic.LoadUint32(&q) == 0 { //drop the first query to trigger health-checking
|
|
|
|
|
atomic.AddUint32(&q, 1)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if r.Question[0].Name == "." && r.RecursionDesired == false {
|
2018-02-15 10:21:57 +01:00
|
|
|
atomic.AddUint32(&i, 1)
|
|
|
|
|
}
|
|
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
|
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealthNoRecursion", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetRecursionDesired(false)
|
2018-02-15 10:21:57 +01:00
|
|
|
f := New()
|
|
|
|
|
f.SetProxy(p)
|
2019-10-01 16:39:42 +01:00
|
|
|
defer f.OnShutdown()
|
2018-02-15 10:21:57 +01:00
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
time.Sleep(20 * time.Millisecond)
|
2018-02-15 10:21:57 +01:00
|
|
|
i1 := atomic.LoadUint32(&i)
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
if i1 != 1 {
|
|
|
|
|
t.Errorf("Expected number of health checks with RecursionDesired==false to be %d, got %d", 1, i1)
|
2018-02-15 10:21:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestHealthTimeout(t *testing.T) {
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
defaultTimeout = 10 * time.Millisecond
|
2018-02-15 10:21:57 +01:00
|
|
|
|
|
|
|
|
i := uint32(0)
|
2018-04-11 09:53:08 +03:00
|
|
|
q := uint32(0)
|
2018-02-15 10:21:57 +01:00
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
if r.Question[0].Name == "." {
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
// health check, answer
|
2018-02-15 10:21:57 +01:00
|
|
|
atomic.AddUint32(&i, 1)
|
|
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
2018-04-11 09:53:08 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if atomic.LoadUint32(&q) == 0 { //drop only first query
|
|
|
|
|
atomic.AddUint32(&q, 1)
|
|
|
|
|
return
|
2018-02-15 10:21:57 +01:00
|
|
|
}
|
2018-04-11 09:53:08 +03:00
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
2018-02-15 10:21:57 +01:00
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealthTimeout", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
2018-02-15 10:21:57 +01:00
|
|
|
f := New()
|
|
|
|
|
f.SetProxy(p)
|
2019-10-01 16:39:42 +01:00
|
|
|
defer f.OnShutdown()
|
2018-02-15 10:21:57 +01:00
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
time.Sleep(20 * time.Millisecond)
|
2018-02-15 10:21:57 +01:00
|
|
|
i1 := atomic.LoadUint32(&i)
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
if i1 != 1 {
|
|
|
|
|
t.Errorf("Expected number of health checks to be %d, got %d", 1, i1)
|
2018-02-15 10:21:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestHealthMaxFails(t *testing.T) {
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
defaultTimeout = 10 * time.Millisecond
|
2023-03-24 12:55:51 +00:00
|
|
|
//,hcInterval = 10 * time.Millisecond
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
|
2018-04-11 09:53:08 +03:00
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
// timeout
|
|
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealthMaxFails", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
2018-04-11 09:53:08 +03:00
|
|
|
f := New()
|
2023-03-24 12:55:51 +00:00
|
|
|
f.hcInterval = 10 * time.Millisecond
|
2018-04-11 09:53:08 +03:00
|
|
|
f.maxfails = 2
|
|
|
|
|
f.SetProxy(p)
|
2019-10-01 16:39:42 +01:00
|
|
|
defer f.OnShutdown()
|
2018-04-11 09:53:08 +03:00
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
2023-03-24 12:55:51 +00:00
|
|
|
fails := p.Fails()
|
2018-04-11 09:53:08 +03:00
|
|
|
if !p.Down(f.maxfails) {
|
2018-11-20 08:48:56 +01:00
|
|
|
t.Errorf("Expected Proxy fails to be greater than %d, got %d", f.maxfails, fails)
|
2018-04-11 09:53:08 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestHealthNoMaxFails(t *testing.T) {
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
defaultTimeout = 10 * time.Millisecond
|
|
|
|
|
|
2018-02-15 10:21:57 +01:00
|
|
|
i := uint32(0)
|
|
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
2018-04-11 09:53:08 +03:00
|
|
|
if r.Question[0].Name == "." {
|
|
|
|
|
// health check, answer
|
|
|
|
|
atomic.AddUint32(&i, 1)
|
|
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
|
|
|
|
}
|
2018-02-15 10:21:57 +01:00
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealthNoMaxFails", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
2018-02-15 10:21:57 +01:00
|
|
|
f := New()
|
|
|
|
|
f.maxfails = 0
|
|
|
|
|
f.SetProxy(p)
|
2019-10-01 16:39:42 +01:00
|
|
|
defer f.OnShutdown()
|
2018-02-15 10:21:57 +01:00
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
time.Sleep(20 * time.Millisecond)
|
2018-02-15 10:21:57 +01:00
|
|
|
i1 := atomic.LoadUint32(&i)
|
Speed up testing (#4239)
* Speed up testing
* make notification run in the background, this recudes the test_readme
time from 18s to 0.10s
* reduce time for zone reload
* TestServeDNSConcurrent remove entirely. This took a whopping 58s for
... ? A few minutes staring didn't reveal wth it is actually testing.
Making values smaller revealed race conditions in the tests. Remove
entirely.
* Move many interval values to variables so we can reset them to short
values for the tests.
* test_large_axfr: make the zone smaller. The number used 64K has no
rational, make it 64/10 to speed up.
* TestProxyThreeWay: use client with shorter timeout
A few random tidbits in other tests.
Total time saved: 177s (almost 3m) - which makes it worthwhile again to
run the test locally:
this branch:
~~~
ok github.com/coredns/coredns/test 10.437s
cd plugin; time go t ./...
5,51s user 7,51s system 11,15s elapsed 744%CPU (
~~~
master:
~~~
ok github.com/coredns/coredns/test 35.252s
cd plugin; time go t ./...
157,64s user 15,39s system 50,05s elapsed 345%CPU ()
~~~
tests/ -25s
plugins/ -40s
This brings the total on 20s, and another 10s can be saved by fixing
dnstapio. Moving this to 5s would be even better, but 10s is also nice.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Also 0.01
Signed-off-by: Miek Gieben <miek@miek.nl>
2020-10-30 10:27:04 +01:00
|
|
|
if i1 != 0 {
|
|
|
|
|
t.Errorf("Expected number of health checks to be %d, got %d", 0, i1)
|
2018-02-15 10:21:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-13 00:39:48 +08:00
|
|
|
|
|
|
|
|
func TestHealthDomain(t *testing.T) {
|
|
|
|
|
defaultTimeout = 10 * time.Millisecond
|
2023-03-24 12:55:51 +00:00
|
|
|
|
2022-04-13 00:39:48 +08:00
|
|
|
hcDomain := "example.org."
|
|
|
|
|
i := uint32(0)
|
|
|
|
|
q := uint32(0)
|
|
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
if atomic.LoadUint32(&q) == 0 { //drop the first query to trigger health-checking
|
|
|
|
|
atomic.AddUint32(&q, 1)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if r.Question[0].Name == hcDomain && r.RecursionDesired == true {
|
|
|
|
|
atomic.AddUint32(&i, 1)
|
|
|
|
|
}
|
|
|
|
|
ret := new(dns.Msg)
|
|
|
|
|
ret.SetReply(r)
|
|
|
|
|
w.WriteMsg(ret)
|
|
|
|
|
})
|
|
|
|
|
defer s.Close()
|
2023-07-04 15:35:55 +01:00
|
|
|
p := proxy.NewProxy("TestHealthDomain", s.Addr, transport.DNS)
|
2023-03-24 12:55:51 +00:00
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetWriteTimeout(10 * time.Millisecond)
|
|
|
|
|
p.GetHealthchecker().SetDomain(hcDomain)
|
2022-04-13 00:39:48 +08:00
|
|
|
f := New()
|
|
|
|
|
f.SetProxy(p)
|
|
|
|
|
defer f.OnShutdown()
|
|
|
|
|
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion(".", dns.TypeNS)
|
|
|
|
|
|
|
|
|
|
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
|
|
|
|
time.Sleep(20 * time.Millisecond)
|
|
|
|
|
i1 := atomic.LoadUint32(&i)
|
|
|
|
|
if i1 != 1 {
|
|
|
|
|
t.Errorf("Expected number of health checks with Domain==%s to be %d, got %d", hcDomain, 1, i1)
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-07 08:37:25 -08:00
|
|
|
|
|
|
|
|
func TestAllUpstreamsDown(t *testing.T) {
|
|
|
|
|
qs := uint32(0)
|
|
|
|
|
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
// count non-healthcheck queries
|
|
|
|
|
if r.Question[0].Name != "." {
|
|
|
|
|
atomic.AddUint32(&qs, 1)
|
|
|
|
|
}
|
|
|
|
|
// timeout
|
|
|
|
|
})
|
|
|
|
|
defer s.Close()
|
|
|
|
|
|
|
|
|
|
s1 := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
|
// count non-healthcheck queries
|
|
|
|
|
if r.Question[0].Name != "." {
|
|
|
|
|
atomic.AddUint32(&qs, 1)
|
|
|
|
|
}
|
|
|
|
|
// timeout
|
|
|
|
|
})
|
|
|
|
|
defer s1.Close()
|
|
|
|
|
|
|
|
|
|
p := proxy.NewProxy("TestHealthAllUpstreamsDown", s.Addr, transport.DNS)
|
|
|
|
|
p1 := proxy.NewProxy("TestHealthAllUpstreamsDown2", s1.Addr, transport.DNS)
|
|
|
|
|
p.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
p1.GetHealthchecker().SetReadTimeout(10 * time.Millisecond)
|
|
|
|
|
|
|
|
|
|
f := New()
|
|
|
|
|
f.SetProxy(p)
|
|
|
|
|
f.SetProxy(p1)
|
|
|
|
|
f.failfastUnhealthyUpstreams = true
|
|
|
|
|
f.maxfails = 1
|
|
|
|
|
// Make proxys fail by checking health twice
|
|
|
|
|
// i.e, fails > maxfails
|
|
|
|
|
for range f.maxfails + 1 {
|
|
|
|
|
p.GetHealthchecker().Check(p)
|
|
|
|
|
p1.GetHealthchecker().Check(p1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer f.OnShutdown()
|
|
|
|
|
|
|
|
|
|
// Check if all proxies are down
|
|
|
|
|
if !p.Down(f.maxfails) || !p1.Down(f.maxfails) {
|
|
|
|
|
t.Fatalf("Expected all proxies to be down")
|
|
|
|
|
}
|
|
|
|
|
req := new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
resp, err := f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
|
|
|
|
|
if resp != dns.RcodeServerFailure {
|
|
|
|
|
t.Errorf("Expected Response code: %d, Got: %d", dns.RcodeServerFailure, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != ErrNoHealthy {
|
|
|
|
|
t.Errorf("Expected error message: no healthy proxies, Got: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
q1 := atomic.LoadUint32(&qs)
|
|
|
|
|
if q1 != 0 {
|
|
|
|
|
t.Errorf("Expected queries to the upstream: 0, Got: %d", q1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set failfast to false to check if queries get answered
|
|
|
|
|
f.failfastUnhealthyUpstreams = false
|
|
|
|
|
|
|
|
|
|
req = new(dns.Msg)
|
|
|
|
|
req.SetQuestion("example.org.", dns.TypeA)
|
|
|
|
|
_, err = f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
|
|
|
|
|
if err == ErrNoHealthy {
|
|
|
|
|
t.Error("Unexpected error message: no healthy proxies")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
q1 = atomic.LoadUint32(&qs)
|
|
|
|
|
if q1 != 1 {
|
|
|
|
|
t.Errorf("Expected queries to the upstream: 1, Got: %d", q1)
|
|
|
|
|
}
|
|
|
|
|
}
|