aboutsummaryrefslogtreecommitdiff
path: root/lib/dns/dns_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-04-08 12:09:22 +0700
committerShulhan <ms@kilabit.info>2019-04-12 19:13:07 +0700
commitfaeaebe07acecd3fa18cc1fdb8e868108d318658 (patch)
treee09e300bc653588be538b5f13b830989a649cbc4 /lib/dns/dns_test.go
parentce558fb263d4bdef58ebfd801331c6b074349f33 (diff)
downloadpakakeh.go-faeaebe07acecd3fa18cc1fdb8e868108d318658.tar.xz
dns: add caches for server
There are two type of answer: local and non-local. Local answer is a DNS record that is loaded from hosts file or master zone file. Non-local answer is a DNS record that is received from parent name servers. Server caches the DNS answers in two storages: map and list. The map caches store local and non local answers, using domain name as a key and list of answers as value, domain-name -> [{A,IN,...},{AAAA,IN,...}] The list caches store non-local answers, ordered by last accessed time, it is used to prune least frequently accessed answers. Local caches will never get pruned.
Diffstat (limited to 'lib/dns/dns_test.go')
-rw-r--r--lib/dns/dns_test.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/dns/dns_test.go b/lib/dns/dns_test.go
index 7929e168..ae2bc0fc 100644
--- a/lib/dns/dns_test.go
+++ b/lib/dns/dns_test.go
@@ -205,16 +205,14 @@ func (h *serverHandler) ServeDNS(req *Request) {
}
func TestMain(m *testing.M) {
+ var err error
+
log.SetFlags(log.Lmicroseconds)
_testHandler = &serverHandler{}
_testHandler.responses = generateTestResponses()
- _testServer = &Server{
- Handler: _testHandler,
- }
-
serverOptions := &ServerOptions{
IPAddress: "127.0.0.1",
UDPPort: 5300,
@@ -225,11 +223,14 @@ func TestMain(m *testing.M) {
DoHAllowInsecure: true,
}
- err := _testServer.Start(serverOptions)
+ _testServer, err = NewServer(serverOptions, _testHandler)
if err != nil {
log.Fatal(err)
}
+ _testServer.Start()
+
+ // Wait for all listeners running.
time.Sleep(500 * time.Millisecond)
s := m.Run()