Fix flaky file-sd test

This commit is contained in:
beorn7 2016-03-07 15:39:18 +01:00
parent 2a2cc52828
commit d44b83690e
1 changed files with 22 additions and 14 deletions

View File

@ -59,23 +59,31 @@ func testFileSD(t *testing.T, ext string) {
} }
newf.Close() newf.Close()
timeout := time.After(15 * time.Second)
// The files contain two target groups. // The files contain two target groups.
select { retry:
case <-time.After(15 * time.Second): for {
t.Fatalf("Expected new target group but got none") select {
case tgs := <-ch: case <-timeout:
tg := tgs[0] 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 { if _, ok := tg.Labels["foo"]; !ok {
t.Fatalf("Label not parsed") t.Fatalf("Label not parsed")
} }
if tg.String() != fmt.Sprintf("fixtures/_test%s:0", ext) { if tg.String() != fmt.Sprintf("fixtures/_test%s:0", ext) {
t.Fatalf("Unexpected target group %s", tg) t.Fatalf("Unexpected target group %s", tg)
} }
tg = tgs[1] tg = tgs[1]
if tg.String() != fmt.Sprintf("fixtures/_test%s:1", ext) { if tg.String() != fmt.Sprintf("fixtures/_test%s:1", ext) {
t.Fatalf("Unexpected target groups %s", tg) t.Fatalf("Unexpected target groups %s", tg)
}
break retry
} }
} }