-
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 (#3330)
Use fixed random sequence to deflake TestTrafficSegmentSplit. Fixes #2665 Signed-off-by: Alexander Yastrebov <[email protected]>
- Loading branch information
1 parent
d8d1bbf
commit 010c033
Showing
4 changed files
with
47 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,22 @@ | ||
package traffic_test | ||
|
||
import ( | ||
"math/rand/v2" | ||
"sync" | ||
) | ||
|
||
// newTestRandFloat64 returns a function that generates fixed sequence of random float64 values for testing. | ||
func newTestRandFloat64() func() float64 { | ||
return rand.New(&lockedSource{s: rand.NewPCG(0x5EED_1, 0x5EED_2)}).Float64 | ||
} | ||
|
||
type lockedSource struct { | ||
mu sync.Mutex | ||
s rand.Source | ||
} | ||
|
||
func (s *lockedSource) Uint64() uint64 { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
return s.s.Uint64() | ||
} |
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