File tree Expand file tree Collapse file tree 1 file changed +24
-9
lines changed Expand file tree Collapse file tree 1 file changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -323,17 +323,32 @@ func TestSearchValue(t *testing.T) {
323
323
t .Error ("error putting value to lan DHT:" , err )
324
324
}
325
325
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
+ }
330
345
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 )
334
349
}
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 " )
337
352
}
338
353
}
339
354
You can’t perform that action at this time.
0 commit comments