Browse Source

e2e: introduce canonical ordering of manifests (#6918)

pull/6920/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
0c3601bcac
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions
  1. +9
    -1
      test/e2e/generator/generate.go
  2. +4
    -0
      test/e2e/generator/main.go
  3. +41
    -0
      test/e2e/pkg/manifest.go

+ 9
- 1
test/e2e/generator/generate.go View File

@ -87,11 +87,19 @@ func Generate(r *rand.Rand, opts Options) ([]e2e.Manifest, error) {
}
manifests = append(manifests, manifest)
}
if opts.Sorted {
// When the sorted flag is set (generally, as long as
// groups arent)
e2e.SortManifests(manifests)
}
return manifests, nil
}
type Options struct {
P2P P2PMode
P2P P2PMode
Sorted bool
}
type P2PMode string


+ 4
- 0
test/e2e/generator/main.go View File

@ -57,6 +57,10 @@ func NewCLI() *CLI {
return fmt.Errorf("p2p mode must be either new, legacy, hybrid or mixed got %s", p2pMode)
}
if groups == 0 {
opts.Sorted = true
}
return cli.generate(dir, groups, opts)
},
}


+ 41
- 0
test/e2e/pkg/manifest.go View File

@ -3,6 +3,7 @@ package e2e
import (
"fmt"
"os"
"sort"
"github.com/BurntSushi/toml"
)
@ -170,3 +171,43 @@ func LoadManifest(file string) (Manifest, error) {
}
return manifest, nil
}
// SortManifests orders (in-place) a list of manifests such that the
// manifests will be ordered (vaguely) from least complex to most
// complex.
func SortManifests(manifests []Manifest) {
sort.SliceStable(manifests, func(i, j int) bool {
left, right := manifests[i], manifests[j]
if len(left.Nodes) < len(right.Nodes) {
return true
}
if left.InitialHeight < right.InitialHeight {
return true
}
if left.TxSize < right.TxSize {
return true
}
if left.Evidence < right.Evidence {
return true
}
var (
leftPerturb int
rightPerturb int
)
for _, n := range left.Nodes {
leftPerturb += len(n.Perturb)
}
for _, n := range right.Nodes {
rightPerturb += len(n.Perturb)
}
return leftPerturb < rightPerturb
})
}

Loading…
Cancel
Save