Skip to content

Commit

Permalink
tests: flaky TestSearchValue (dual)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Mar 5, 2025
1 parent 1fab30b commit 1cbf728
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions dual/dual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,32 @@ func TestSearchValue(t *testing.T) {
t.Error("error putting value to lan DHT:", err)
}

valCh, err = d.SearchValue(ctx, "/v/hello", dht.Quorum(0))
if err != nil {
t.Fatal(err)
}
maxAttempts := 5
success := false
// if value not propagated yet, try again to avoid flakiness
for i := 0; i < maxAttempts; i++ {
valCh, err = d.SearchValue(ctx, "/v/hello", dht.Quorum(0))
if err != nil {
t.Fatal(err)
}

var lastVal []byte
vals := make([]string, 0)
for c := range valCh {
lastVal = c
vals = append(vals, string(c))
}
if string(lastVal) == "newer" {
success = true
break
}

var lastVal []byte
for c := range valCh {
lastVal = c
t.Log(vals)
t.Log("incorrect best search value", string(lastVal))
time.Sleep(5 * time.Millisecond)
}
if string(lastVal) != "newer" {
t.Fatal("incorrect best search value")
if !success {
t.Fatal("fatal: incorrect best search value", maxAttempts, "times")
}
}

Expand Down

0 comments on commit 1cbf728

Please sign in to comment.