one meaningless write to the config file to trigger anothe fsnotify (#3492)

This commit is contained in:
Krasi Georgiev 2017-12-01 17:32:27 +00:00 committed by Brian Brazil
parent cae4538b3e
commit 29506e0bca

View file

@ -76,6 +76,7 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) {
}() }()
newf, err := os.Create(filepath.Join(testDir, "_test_"+prefix+ext)) newf, err := os.Create(filepath.Join(testDir, "_test_"+prefix+ext))
defer newf.Close()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -90,14 +91,13 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) {
t.Fatal(err) t.Fatal(err)
} }
// File is written with the config so stop draining the discovery channel. // Test file is ready so stop draining the discovery channel.
// It needs to be before the file closing so that fsnotify triggers a new loop of the discovery service. // It contains two target groups.
close(fileReady) close(fileReady)
<-drainReady <-drainReady
newf.Close() newf.WriteString(" ") // One last meaningless write to trigger fsnotify and a new loop of the discovery service.
timeout := time.After(15 * time.Second) timeout := time.After(15 * time.Second)
// The files contain two target groups.
retry: retry:
for { for {
select { select {
@ -105,7 +105,7 @@ retry:
if expect { if expect {
t.Fatalf("Expected new target group but got none") t.Fatalf("Expected new target group but got none")
} else { } else {
// invalid type fsd should always broken down. // Invalid type fsd should always break down.
break retry break retry
} }
case tgs := <-ch: case tgs := <-ch: