Skip to content

Commit 0dfc7ab

Browse files
authored
Merge pull request #19388 from ahrtr/refactor_20250211
Minor refacotr on the e2e test framework
2 parents 53d44f0 + 5703e6b commit 0dfc7ab

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

tests/framework/e2e/cluster.go

+32-23
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,6 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
457457
if cfg.Version == LastVersion && !CouldSetSnapshotCatchupEntries(BinPath.EtcdLastRelease) {
458458
return nil, fmt.Errorf("cannot set SnapshotCatchUpEntries for last etcd version: %s", BinPath.EtcdLastRelease)
459459
}
460-
if cfg.Version != CurrentVersion && UsesExperimentalSnapshotCatchupEntriesFlag(BinPath.EtcdLastRelease) {
461-
cfg.ServerConfig.ExperimentalSnapshotCatchUpEntries = cfg.ServerConfig.SnapshotCatchUpEntries
462-
cfg.ServerConfig.SnapshotCatchUpEntries = etcdserver.DefaultSnapshotCatchUpEntries
463-
}
464460
}
465461

466462
etcdCfgs := cfg.EtcdAllServerProcessConfigs(t)
@@ -639,26 +635,13 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
639635
args = append(args, "--discovery="+cfg.Discovery)
640636
}
641637

642-
var execPath string
643-
switch cfg.Version {
644-
case CurrentVersion:
645-
execPath = BinPath.Etcd
646-
case MinorityLastVersion:
647-
if i <= cfg.ClusterSize/2 {
648-
execPath = BinPath.Etcd
649-
} else {
650-
execPath = BinPath.EtcdLastRelease
651-
}
652-
case QuorumLastVersion:
653-
if i <= cfg.ClusterSize/2 {
654-
execPath = BinPath.EtcdLastRelease
655-
} else {
656-
execPath = BinPath.Etcd
638+
execPath := cfg.binaryPath(i)
639+
640+
if cfg.ServerConfig.SnapshotCatchUpEntries != etcdserver.DefaultSnapshotCatchUpEntries {
641+
if !IsSnapshotCatchupEntriesFlagAvailable(execPath) {
642+
cfg.ServerConfig.ExperimentalSnapshotCatchUpEntries = cfg.ServerConfig.SnapshotCatchUpEntries
643+
cfg.ServerConfig.SnapshotCatchUpEntries = etcdserver.DefaultSnapshotCatchUpEntries
657644
}
658-
case LastVersion:
659-
execPath = BinPath.EtcdLastRelease
660-
default:
661-
panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version))
662645
}
663646

664647
defaultValues := values(*embed.NewConfig())
@@ -702,6 +685,32 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
702685
}
703686
}
704687

688+
func (cfg *EtcdProcessClusterConfig) binaryPath(i int) string {
689+
var execPath string
690+
switch cfg.Version {
691+
case CurrentVersion:
692+
execPath = BinPath.Etcd
693+
case MinorityLastVersion:
694+
if i <= cfg.ClusterSize/2 {
695+
execPath = BinPath.Etcd
696+
} else {
697+
execPath = BinPath.EtcdLastRelease
698+
}
699+
case QuorumLastVersion:
700+
if i <= cfg.ClusterSize/2 {
701+
execPath = BinPath.EtcdLastRelease
702+
} else {
703+
execPath = BinPath.Etcd
704+
}
705+
case LastVersion:
706+
execPath = BinPath.EtcdLastRelease
707+
default:
708+
panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version))
709+
}
710+
711+
return execPath
712+
}
713+
705714
func values(cfg embed.Config) map[string]string {
706715
fs := flag.NewFlagSet("etcd", flag.ContinueOnError)
707716
cfg.AddFlags(fs)

tests/framework/e2e/cluster_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestEtcdServerProcessConfig(t *testing.T) {
8181
name: "CatchUpEntries",
8282
config: NewConfig(WithSnapshotCatchUpEntries(100)),
8383
expectArgsContain: []string{
84-
"--snapshot-catchup-entries=100",
84+
"--experimental-snapshot-catchup-entries=100",
8585
},
8686
mockBinaryVersion: &v3_5_14,
8787
},

tests/framework/e2e/etcd_process.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/coreos/go-semver/semver"
3232
"go.uber.org/zap"
3333

34+
"go.etcd.io/etcd/api/v3/version"
3435
"go.etcd.io/etcd/client/pkg/v3/fileutil"
3536
"go.etcd.io/etcd/pkg/v3/expect"
3637
"go.etcd.io/etcd/pkg/v3/proxy"
@@ -532,11 +533,10 @@ func CouldSetSnapshotCatchupEntries(execPath string) bool {
532533
return v.Compare(v3_5_14) >= 0
533534
}
534535

535-
func UsesExperimentalSnapshotCatchupEntriesFlag(execPath string) bool {
536+
func IsSnapshotCatchupEntriesFlagAvailable(execPath string) bool {
536537
v, err := GetVersionFromBinary(execPath)
537538
if err != nil {
538539
return false
539540
}
540-
v3_6 := semver.Version{Major: 3, Minor: 6}
541-
return v.LessThan(v3_6)
541+
return !v.LessThan(version.V3_6)
542542
}

0 commit comments

Comments
 (0)