From 29506e0bca5491aa7d0c28e6a020822c4de8bfe9 Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Fri, 1 Dec 2017 17:32:27 +0000 Subject: [PATCH] one meaningless write to the config file to trigger anothe fsnotify (#3492) --- discovery/file/file_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discovery/file/file_test.go b/discovery/file/file_test.go index 2305a0684..6ac5aa7e9 100644 --- a/discovery/file/file_test.go +++ b/discovery/file/file_test.go @@ -76,6 +76,7 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) { }() newf, err := os.Create(filepath.Join(testDir, "_test_"+prefix+ext)) + defer newf.Close() if err != nil { t.Fatal(err) } @@ -90,14 +91,13 @@ func testFileSD(t *testing.T, prefix, ext string, expect bool) { t.Fatal(err) } - // File is written with the config 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. + // Test file is ready so stop draining the discovery channel. + // It contains two target groups. close(fileReady) <-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) - // The files contain two target groups. retry: for { select { @@ -105,7 +105,7 @@ retry: if expect { t.Fatalf("Expected new target group but got none") } else { - // invalid type fsd should always broken down. + // Invalid type fsd should always break down. break retry } case tgs := <-ch: