aboutsummaryrefslogtreecommitdiff
path: root/test/proxy_health_test.go
blob: 1438466884997f1bd2223096e53b5a0b5e610fd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package test

import (
	"io/ioutil"
	"log"
	"testing"

	"github.com/miekg/coredns/middleware/proxy"
	"github.com/miekg/coredns/middleware/test"
	"github.com/miekg/coredns/request"

	"github.com/miekg/dns"
)

func TestProxyErratic(t *testing.T) {
	log.SetOutput(ioutil.Discard)

	corefile := `example.org:0 {
		erratic {
			drop 2
		}
	}
`

	backend, err := CoreDNSServer(corefile)
	if err != nil {
		t.Fatalf("Could not get CoreDNS serving instance: %s", err)
	}

	udp, _ := CoreDNSServerPorts(backend, 0)
	if udp == "" {
		t.Fatalf("Could not get UDP listening port")
	}
	defer backend.Stop()

	p := proxy.New([]string{udp})
	state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}

	// We do one lookup that should not time out.
	// After this the backend is marked unhealthy anyway. So basically this
	// tests that it times out.
	p.Lookup(state, "example.org.", dns.TypeA)
}