mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-25 09:24:30 +00:00
e2e: add weighted random configuration selector (#6869)
When revwing #6807 I assumed that `probSetChoice` worked this way. I think that the coverage of various configuration options should generally track what we expect the actual useage to be to focus the most test coverage on the configurations that are the most prevelent.
This commit is contained in:
@@ -26,7 +26,13 @@ var (
|
||||
}
|
||||
|
||||
// The following specify randomly chosen values for testnet nodes.
|
||||
nodeDatabases = uniformChoice{"goleveldb", "cleveldb", "rocksdb", "boltdb", "badgerdb"}
|
||||
nodeDatabases = weightedChoice{
|
||||
"goleveldb": 35,
|
||||
"badgerdb": 35,
|
||||
"boltdb": 15,
|
||||
"rocksdb": 10,
|
||||
"cleveldb": 5,
|
||||
}
|
||||
nodeABCIProtocols = uniformChoice{"unix", "tcp", "builtin", "grpc"}
|
||||
nodePrivvalProtocols = uniformChoice{"file", "unix", "tcp", "grpc"}
|
||||
// FIXME: v2 disabled due to flake
|
||||
@@ -270,7 +276,7 @@ func generateNode(
|
||||
node := e2e.ManifestNode{
|
||||
Mode: string(mode),
|
||||
StartAt: startAt,
|
||||
Database: nodeDatabases.Choose(r).(string),
|
||||
Database: nodeDatabases.Choose(r),
|
||||
ABCIProtocol: nodeABCIProtocols.Choose(r).(string),
|
||||
PrivvalProtocol: nodePrivvalProtocols.Choose(r).(string),
|
||||
BlockSync: nodeBlockSyncs.Choose(r).(string),
|
||||
@@ -321,7 +327,7 @@ func generateLightNode(r *rand.Rand, startAt int64, providers []string) *e2e.Man
|
||||
return &e2e.ManifestNode{
|
||||
Mode: string(e2e.ModeLight),
|
||||
StartAt: startAt,
|
||||
Database: nodeDatabases.Choose(r).(string),
|
||||
Database: nodeDatabases.Choose(r),
|
||||
ABCIProtocol: "builtin",
|
||||
PersistInterval: ptrUint64(0),
|
||||
PersistentPeers: providers,
|
||||
|
||||
@@ -3,6 +3,8 @@ package main
|
||||
import (
|
||||
"math/rand"
|
||||
"sort"
|
||||
|
||||
"github.com/mroth/weightedrand"
|
||||
)
|
||||
|
||||
// combinations takes input in the form of a map of item lists, and returns a
|
||||
@@ -83,3 +85,19 @@ func (usc uniformSetChoice) Choose(r *rand.Rand) []string {
|
||||
}
|
||||
return choices
|
||||
}
|
||||
|
||||
type weightedChoice map[string]uint
|
||||
|
||||
func (wc weightedChoice) Choose(r *rand.Rand) string {
|
||||
choices := make([]weightedrand.Choice, 0, len(wc))
|
||||
for k, v := range wc {
|
||||
choices = append(choices, weightedrand.NewChoice(k, v))
|
||||
}
|
||||
|
||||
chooser, err := weightedrand.NewChooser(choices...)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return chooser.PickSource(r).(string)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user