Skip to content

Commit 64ea67f

Browse files
tests: flaky TestSearchValue (dual) (#1060)
1 parent 1fab30b commit 64ea67f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

dual/dual_test.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,32 @@ func TestSearchValue(t *testing.T) {
323323
t.Error("error putting value to lan DHT:", err)
324324
}
325325

326-
valCh, err = d.SearchValue(ctx, "/v/hello", dht.Quorum(0))
327-
if err != nil {
328-
t.Fatal(err)
329-
}
326+
maxAttempts := 5
327+
success := false
328+
// if value not propagated yet, try again to avoid flakiness
329+
for i := 0; i < maxAttempts; i++ {
330+
valCh, err = d.SearchValue(ctx, "/v/hello", dht.Quorum(0))
331+
if err != nil {
332+
t.Fatal(err)
333+
}
334+
335+
var lastVal []byte
336+
vals := make([]string, 0)
337+
for c := range valCh {
338+
lastVal = c
339+
vals = append(vals, string(c))
340+
}
341+
if string(lastVal) == "newer" {
342+
success = true
343+
break
344+
}
330345

331-
var lastVal []byte
332-
for c := range valCh {
333-
lastVal = c
346+
t.Log(vals)
347+
t.Log("incorrect best search value", string(lastVal))
348+
time.Sleep(5 * time.Millisecond)
334349
}
335-
if string(lastVal) != "newer" {
336-
t.Fatal("incorrect best search value")
350+
if !success {
351+
t.Fatal("fatal: incorrect best search value", maxAttempts, "times")
337352
}
338353
}
339354

0 commit comments

Comments
 (0)