Merge pull request #1030 from prometheus/fix-flakey-filesd

Fix flakey FileSD test.
This commit is contained in:
Julius Volz 2015-08-26 13:25:00 +02:00
commit 29eaa8c7cf
2 changed files with 5 additions and 4 deletions

View File

@ -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{}

View File

@ -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
}