middleware/file: add test for reload (#361)

This add a highlevel integration test for zone reloading. It also
fixes a data race in the actual reloading process.
This commit is contained in:
Miek Gieben 2016-10-27 21:01:04 +01:00 committed by GitHub
parent 94dc28646d
commit 039596f319
3 changed files with 97 additions and 2 deletions

View file

@ -163,22 +163,24 @@ func (z *Zone) Reload() error {
select {
case event := <-watcher.Events:
if event.Op == fsnotify.Write && path.Clean(event.Name) == z.file {
reader, err := os.Open(z.file)
if err != nil {
log.Printf("[ERROR] Failed to open `%s' for `%s': %v", z.file, z.origin, err)
continue
}
z.reloadMu.Lock()
zone, err := Parse(reader, z.origin, z.file)
if err != nil {
log.Printf("[ERROR] Failed to parse `%s': %v", z.origin, err)
z.reloadMu.Unlock()
continue
}
// copy elements we need
z.reloadMu.Lock()
z.Apex = zone.Apex
z.Tree = zone.Tree
z.reloadMu.Unlock()
log.Printf("[INFO] Successfully reloaded zone `%s'", z.origin)
z.Notify()
}