mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	* plugin/{file,auto}: drop fsnotify
Reload every minute. This is more deterministic then fsnotify. Also
other thing cropped up: sharing zone files between zone; there is only
1 fsnotify event and we need to fan out the reload to all zone files.
This is a large rewrite (which could still be done), for now, poll the
zone file on disk.
Give serial no change a special error type so we can check for this.
Improve the logging for reloading:
2017/09/19 07:34:39 [INFO] Successfully reloaded zone "miek.nl." in "db.miek.nl" with serial 128263060
2017/09/19 07:34:45 [INFO] Successfully reloaded zone "miek.nl." in "db.miek.nl" with serial 128263059
2017/09/19 07:34:51 [INFO] Successfully reloaded zone "miek.nl." in "db.miek.nl" with serial 128263060
Fixes #1013
* typo
		
	
		
			
				
	
	
		
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package test
 | 
						|
 | 
						|
import (
 | 
						|
	"io/ioutil"
 | 
						|
	"testing"
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/coredns/coredns/plugin/file"
 | 
						|
	"github.com/coredns/coredns/plugin/proxy"
 | 
						|
	"github.com/coredns/coredns/plugin/test"
 | 
						|
	"github.com/coredns/coredns/request"
 | 
						|
 | 
						|
	"github.com/miekg/dns"
 | 
						|
)
 | 
						|
 | 
						|
func TestZoneReload(t *testing.T) {
 | 
						|
	file.TickTime = 1 * time.Second
 | 
						|
 | 
						|
	name, rm, err := TempFile(".", exampleOrg)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatalf("Failed to create zone: %s", err)
 | 
						|
	}
 | 
						|
	defer rm()
 | 
						|
 | 
						|
	// Corefile with two stanzas
 | 
						|
	corefile := `example.org:0 {
 | 
						|
       file ` + name + `
 | 
						|
}
 | 
						|
 | 
						|
example.net:0 {
 | 
						|
	file ` + name + `
 | 
						|
}
 | 
						|
`
 | 
						|
	i, udp, _, err := CoreDNSServerAndPorts(corefile)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatalf("Could not get CoreDNS serving instance: %s", err)
 | 
						|
	}
 | 
						|
	defer i.Stop()
 | 
						|
 | 
						|
	p := proxy.NewLookup([]string{udp})
 | 
						|
	state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
 | 
						|
 | 
						|
	resp, err := p.Lookup(state, "example.org.", dns.TypeA)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatalf("Expected to receive reply, but didn't: %s", err)
 | 
						|
	}
 | 
						|
	if len(resp.Answer) != 2 {
 | 
						|
		t.Fatalf("Expected two RR in answer section got %d", len(resp.Answer))
 | 
						|
	}
 | 
						|
 | 
						|
	// Remove RR from the Apex
 | 
						|
	ioutil.WriteFile(name, []byte(exampleOrgUpdated), 0644)
 | 
						|
 | 
						|
	time.Sleep(2 * time.Second) // reload time
 | 
						|
 | 
						|
	resp, err = p.Lookup(state, "example.org.", dns.TypeA)
 | 
						|
	if err != nil {
 | 
						|
		t.Fatal("Expected to receive reply, but didn't")
 | 
						|
	}
 | 
						|
 | 
						|
	if len(resp.Answer) != 1 {
 | 
						|
		t.Fatalf("Expected two RR in answer section got %d", len(resp.Answer))
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
const exampleOrgUpdated = `; example.org test file
 | 
						|
example.org.		IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2016082541 7200 3600 1209600 3600
 | 
						|
example.org.		IN	NS	b.iana-servers.net.
 | 
						|
example.org.		IN	NS	a.iana-servers.net.
 | 
						|
example.org.		IN	A	127.0.0.2
 | 
						|
`
 |