diff --git a/retrieval/discovery/file.go b/retrieval/discovery/file.go index 91fcceb92..db138d56c 100644 --- a/retrieval/discovery/file.go +++ b/retrieval/discovery/file.go @@ -160,7 +160,7 @@ func (fd *FileDiscovery) Run(ch chan<- *config.TargetGroup, done <-chan struct{} } } -// refresh reads all files matching the discoveries patterns and sends the respective +// refresh reads all files matching the discovery's patterns and sends the respective // updated target groups through the channel. func (fd *FileDiscovery) refresh(ch chan<- *config.TargetGroup) { ref := map[string]int{} diff --git a/retrieval/discovery/file_test.go b/retrieval/discovery/file_test.go index 49e4fb175..1928917fb 100644 --- a/retrieval/discovery/file_test.go +++ b/retrieval/discovery/file_test.go @@ -30,7 +30,6 @@ func testFileSD(t *testing.T, ext string) { done = make(chan struct{}) ) go fsd.Run(ch, done) - defer close(done) select { case <-time.After(25 * time.Millisecond): @@ -81,6 +80,7 @@ func testFileSD(t *testing.T, ext string) { // some runs (which might be empty, chains of different operations etc.). // We have to drain those (as the target manager would) to avoid deadlocking and must // not try to make sense of it all... + drained := make(chan struct{}) go func() { for tg := range ch { // Below we will change the file to a bad syntax. Previously extracted target @@ -89,6 +89,7 @@ func testFileSD(t *testing.T, ext string) { t.Errorf("Unexpected empty target group received: %s", tg) } } + close(drained) }() newf, err = os.Create("fixtures/_test.new") @@ -104,6 +105,6 @@ func testFileSD(t *testing.T, ext string) { os.Rename(newf.Name(), "fixtures/_test"+ext) - // Give notifcations some time to arrive. - time.Sleep(50 * time.Millisecond) + close(done) + <-drained }