Merge pull request #1465 from prometheus/beorn7/fix-test2

Fix flaky file-sd test
This commit is contained in:
Fabian Reinartz 2016-03-07 15:46:18 +01:00
commit 6bbb4af837
1 changed files with 22 additions and 14 deletions

View File

@ -59,11 +59,17 @@ func testFileSD(t *testing.T, ext string) {
}
newf.Close()
timeout := time.After(15 * time.Second)
// The files contain two target groups.
retry:
for {
select {
case <-time.After(15 * time.Second):
case <-timeout:
t.Fatalf("Expected new target group but got none")
case tgs := <-ch:
if len(tgs) != 2 {
continue retry // Potentially a partial write, just retry.
}
tg := tgs[0]
if _, ok := tg.Labels["foo"]; !ok {
@ -77,6 +83,8 @@ func testFileSD(t *testing.T, ext string) {
if tg.String() != fmt.Sprintf("fixtures/_test%s:1", ext) {
t.Fatalf("Unexpected target groups %s", tg)
}
break retry
}
}
// Based on unknown circumstances, sometimes fsnotify will trigger more events in