Skip to content

Commit

Permalink
Add randomness in robustness cluster process version to test mixed ve…
Browse files Browse the repository at this point in the history
…rsion scenarios.

Signed-off-by: Siyuan Zhang <[email protected]>
  • Loading branch information
siyuanfoundation committed May 1, 2024
1 parent 8e41a69 commit f18395e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"flag"
"fmt"
"math/rand"
"net/url"
"path"
"path/filepath"
Expand All @@ -31,6 +32,7 @@ import (
"go.uber.org/zap/zaptest"

"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/client/pkg/v3/fileutil"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/proxy"
"go.etcd.io/etcd/server/v3/embed"
Expand Down Expand Up @@ -148,6 +150,9 @@ type EtcdProcessClusterConfig struct {

EnvVars map[string]string
Version ClusterVersion
// LastReleaseProbability is the probability of a process with the last release binary,
// used in combination with Version = Random.
LastReleaseProbability float64

// Cluster setup config

Expand Down Expand Up @@ -207,6 +212,10 @@ func WithVersion(version ClusterVersion) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.Version = version }
}

func WithLastReleaseProbability(prob float64) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.LastReleaseProbability = prob }
}

func WithDataDirPath(path string) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.BaseDataDirPath = path }
}
Expand Down Expand Up @@ -609,6 +618,8 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
}
case LastVersion:
execPath = BinPath.EtcdLastRelease
case Random:
execPath = pickRandomVersion(cfg.Logger, cfg.LastReleaseProbability)
default:
panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version))
}
Expand All @@ -635,6 +646,25 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
}
}

func pickRandomVersion(lg *zap.Logger, lastReleaseProbability float64) string {
execPath := BinPath.Etcd
if !fileutil.Exist(BinPath.EtcdLastRelease) {
lg.Warn("EtcdLastRelease needs to exist to use Random version. Falling back to CurrentVersion", zap.String("EtcdLastRelease-path", BinPath.EtcdLastRelease))
return execPath
}
if lastReleaseProbability < 0 || lastReleaseProbability > 1 {
panic(fmt.Sprintf("LastReleaseProbability has to be between [0, 1.0], got %v", lastReleaseProbability))
}
r := rand.Float64()
if r < lastReleaseProbability {
execPath = BinPath.EtcdLastRelease
} else {
execPath = BinPath.Etcd
}
lg.Info("picked random process binary path", zap.String("exec-path", execPath), zap.Float64("LastReleaseProbability", lastReleaseProbability))
return execPath
}

func values(cfg embed.Config) map[string]string {
fs := flag.NewFlagSet("etcd", flag.ContinueOnError)
cfg.AddFlags(fs)
Expand Down
1 change: 1 addition & 0 deletions tests/framework/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
MinorityLastVersion ClusterVersion = "minority-last-version"
QuorumLastVersion ClusterVersion = "quorum-last-version"
LastVersion ClusterVersion = "last-version"
Random ClusterVersion = "random"
)

type ClusterContext struct {
Expand Down
3 changes: 3 additions & 0 deletions tests/robustness/scenarios.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func exploratoryScenarios(t *testing.T) []testScenario {
if !v.LessThan(version.V3_6) {
clusterOfSize3Options = append(clusterOfSize3Options, e2e.WithSnapshotCatchUpEntries(100))
}
if !v.LessThan(version.V3_5) {
clusterOfSize3Options = append(clusterOfSize3Options, e2e.WithVersion(e2e.Random), e2e.WithLastReleaseProbability(0.1))
}
scenarios = append(scenarios, testScenario{
name: name,
traffic: tp.Traffic,
Expand Down

0 comments on commit f18395e

Please sign in to comment.