mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 06:15:33 +00:00
e2e: add limit and sort to generator (#6998)
I observed a couple of problems with the generator in some recent tests: - there were a couple of hybrid test cases which did not have any legacy nodes (randomness and all.) I change the probability to produce more reliable results. - added options to the generation to be able to add a max (to compliment the earlier min) number of nodes for local testing. - added an option to support reversing the sort order so "more complex" networks were first, as well as tweaked some of the point values. - this refactored the generators cli parsing to be a bit more clear.
This commit is contained in:
@@ -90,6 +90,10 @@ func Generate(r *rand.Rand, opts Options) ([]e2e.Manifest, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if opts.MaxNetworkSize > 0 && len(manifest.Nodes) >= opts.MaxNetworkSize {
|
||||
continue
|
||||
}
|
||||
|
||||
manifests = append(manifests, manifest)
|
||||
}
|
||||
|
||||
@@ -98,9 +102,11 @@ func Generate(r *rand.Rand, opts Options) ([]e2e.Manifest, error) {
|
||||
|
||||
type Options struct {
|
||||
MinNetworkSize int
|
||||
MaxNetworkSize int
|
||||
NumGroups int
|
||||
Directory string
|
||||
P2P P2PMode
|
||||
Reverse bool
|
||||
}
|
||||
|
||||
type P2PMode string
|
||||
@@ -159,7 +165,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
|
||||
case LegacyP2PMode:
|
||||
node.UseLegacyP2P = true
|
||||
case HybridP2PMode:
|
||||
node.UseLegacyP2P = r.Intn(2) == 1
|
||||
node.UseLegacyP2P = r.Intn(5) < 2
|
||||
}
|
||||
|
||||
manifest.Nodes[fmt.Sprintf("seed%02d", i)] = node
|
||||
@@ -184,7 +190,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
|
||||
case LegacyP2PMode:
|
||||
node.UseLegacyP2P = true
|
||||
case HybridP2PMode:
|
||||
node.UseLegacyP2P = r.Intn(2) == 1
|
||||
node.UseLegacyP2P = r.Intn(5) < 2
|
||||
}
|
||||
|
||||
manifest.Nodes[name] = node
|
||||
@@ -221,7 +227,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}) (e2e.Manifest, er
|
||||
case LegacyP2PMode:
|
||||
node.UseLegacyP2P = true
|
||||
case HybridP2PMode:
|
||||
node.UseLegacyP2P = r.Intn(2) == 1
|
||||
node.UseLegacyP2P = r.Intn(5) < 2
|
||||
}
|
||||
|
||||
manifest.Nodes[fmt.Sprintf("full%02d", i)] = node
|
||||
|
||||
@@ -41,25 +41,11 @@ func NewCLI() *CLI {
|
||||
var opts Options
|
||||
var err error
|
||||
|
||||
cli.opts.Directory, err = cmd.Flags().GetString("dir")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cli.opts.NumGroups, err = cmd.Flags().GetInt("groups")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cli.opts.MinNetworkSize, err = cmd.Flags().GetInt("min-size")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p2pMode, err := cmd.Flags().GetString("p2p")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch mode := P2PMode(p2pMode); mode {
|
||||
case NewP2PMode, LegacyP2PMode, HybridP2PMode, MixedP2PMode:
|
||||
opts.P2P = mode
|
||||
@@ -71,12 +57,16 @@ func NewCLI() *CLI {
|
||||
},
|
||||
}
|
||||
|
||||
cli.root.PersistentFlags().StringP("dir", "d", "", "Output directory for manifests")
|
||||
cli.root.PersistentFlags().StringVarP(&cli.opts.Directory, "dir", "d", "", "Output directory for manifests")
|
||||
_ = cli.root.MarkPersistentFlagRequired("dir")
|
||||
cli.root.PersistentFlags().IntP("groups", "g", 0, "Number of groups")
|
||||
cli.root.Flags().BoolVarP(&cli.opts.Reverse, "reverse", "r", false, "Reverse sort order")
|
||||
cli.root.PersistentFlags().IntVarP(&cli.opts.NumGroups, "groups", "g", 0, "Number of groups")
|
||||
cli.root.PersistentFlags().StringP("p2p", "p", string(MixedP2PMode),
|
||||
"P2P typology to be generated [\"new\", \"legacy\", \"hybrid\" or \"mixed\" ]")
|
||||
cli.root.PersistentFlags().IntP("min-size", "m", 1, "Minimum Network Size")
|
||||
cli.root.PersistentFlags().IntVarP(&cli.opts.MinNetworkSize, "min-size", "", 1,
|
||||
"Minimum network size (nodes)")
|
||||
cli.root.PersistentFlags().IntVarP(&cli.opts.MaxNetworkSize, "max-size", "", 0,
|
||||
"Maxmum network size (nodes), 0 is unlimited")
|
||||
|
||||
return cli
|
||||
}
|
||||
@@ -95,7 +85,7 @@ func (cli *CLI) generate() error {
|
||||
|
||||
switch {
|
||||
case cli.opts.NumGroups <= 0:
|
||||
e2e.SortManifests(manifests)
|
||||
e2e.SortManifests(manifests, cli.opts.Reverse)
|
||||
|
||||
if err := e2e.WriteManifests(filepath.Join(cli.opts.Directory, "gen"), manifests); err != nil {
|
||||
return err
|
||||
@@ -104,7 +94,7 @@ func (cli *CLI) generate() error {
|
||||
groupManifests := e2e.SplitGroups(cli.opts.NumGroups, manifests)
|
||||
|
||||
for idx, gm := range groupManifests {
|
||||
e2e.SortManifests(gm)
|
||||
e2e.SortManifests(gm, cli.opts.Reverse)
|
||||
|
||||
prefix := filepath.Join(cli.opts.Directory, fmt.Sprintf("gen-group%02d", idx))
|
||||
if err := e2e.WriteManifests(prefix, gm); err != nil {
|
||||
|
||||
@@ -172,8 +172,11 @@ func LoadManifest(file string) (Manifest, error) {
|
||||
// SortManifests orders (in-place) a list of manifests such that the
|
||||
// manifests will be ordered in terms of complexity (or expected
|
||||
// runtime). Complexity is determined first by the number of nodes,
|
||||
// and then by the total number of perturbations in the network
|
||||
func SortManifests(manifests []Manifest) {
|
||||
// and then by the total number of perturbations in the network.
|
||||
//
|
||||
// If reverse is true, then the manifests are ordered with the most
|
||||
// complex networks before the less complex networks.
|
||||
func SortManifests(manifests []Manifest, reverse bool) {
|
||||
sort.SliceStable(manifests, func(i, j int) bool {
|
||||
// sort based on a point-based comparison between two
|
||||
// manifests.
|
||||
@@ -194,24 +197,37 @@ func SortManifests(manifests []Manifest) {
|
||||
leftScore += (len(n.Perturb) * 2)
|
||||
|
||||
if n.StartAt > 0 {
|
||||
leftScore++
|
||||
leftScore += 3
|
||||
}
|
||||
}
|
||||
for _, n := range right.Nodes {
|
||||
rightScore += (len(n.Perturb) * 2)
|
||||
if n.StartAt > 0 {
|
||||
rightScore++
|
||||
rightScore += 3
|
||||
}
|
||||
}
|
||||
|
||||
// add one point if the network has evidence.
|
||||
if left.Evidence > 0 {
|
||||
leftScore += 2
|
||||
}
|
||||
|
||||
if right.Evidence > 0 {
|
||||
rightScore += 2
|
||||
}
|
||||
|
||||
if left.TxSize > right.TxSize {
|
||||
leftScore++
|
||||
}
|
||||
if right.Evidence > 0 {
|
||||
|
||||
if right.TxSize > left.TxSize {
|
||||
rightScore++
|
||||
}
|
||||
|
||||
if reverse {
|
||||
return leftScore >= rightScore
|
||||
}
|
||||
|
||||
return leftScore < rightScore
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user