-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
predicates/traffic: deflake TestTrafficSegmentSplit
Use fixed random sequence to deflake TestTrafficSegmentSplit. Fixes #2665 Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
- Loading branch information
1 parent
e2973de
commit 309fe1f
Showing
4 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
package traffic | ||
|
||
import "github.com/zalando/skipper/routing" | ||
|
||
var ExportRandomValue = randomValue | ||
|
||
func WithRandFloat64(ps routing.PredicateSpec, randFloat64 func() float64) routing.PredicateSpec { | ||
if s, ok := ps.(*segmentSpec); ok { | ||
s.randFloat64 = randFloat64 | ||
} else { | ||
panic("invalid predicate spec, expected *segmentSpec") | ||
} | ||
return ps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package traffic_test | ||
|
||
import ( | ||
"math/rand/v2" | ||
"sync" | ||
) | ||
|
||
var ( | ||
testRandMu sync.Mutex | ||
testRand = rand.New(rand.NewPCG(0x5EED_1, 0x5EED_2)) | ||
) | ||
|
||
// testRandFloat64 is a helper function to generate fixed sequence of random float64 values for testing. | ||
func testRandFloat64() float64 { | ||
testRandMu.Lock() | ||
defer testRandMu.Unlock() | ||
return testRand.Float64() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters