test: add ClusterContext into the common ClusterConfig

ClusterContext is used by "e2e" or "integration" to extend the
ClusterConfig. The common test cases shouldn't care about what
data is encoded or included; instead "e2e" or "integration"
framework should decode or parse it separately.

Signed-off-by: Benjamin Wang <wachao@vmware.com>
dependabot/go_modules/go.uber.org/atomic-1.10.0
Benjamin Wang 2022-11-07 10:05:45 +08:00
parent 71b40b3abf
commit fc23d0e83a
6 changed files with 49 additions and 25 deletions

View File

@ -52,21 +52,22 @@ func e2eClusterTestCases() []testCase {
config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS},
},
}
if fileutil.Exist(e2e.BinPath.EtcdLastRelease) {
tcs = append(tcs, testCase{
name: "MinorityLastVersion",
config: config.ClusterConfig{
ClusterSize: 3,
E2eConfig: &config.E2eClusterConfig{
Version: config.MinorityLastVersion,
ClusterContext: &e2e.ClusterContext{
Version: e2e.MinorityLastVersion,
},
},
}, testCase{
name: "QuorumLastVersion",
config: config.ClusterConfig{
ClusterSize: 3,
E2eConfig: &config.E2eClusterConfig{
Version: config.QuorumLastVersion,
ClusterContext: &e2e.ClusterContext{
Version: e2e.QuorumLastVersion,
},
},
})

View File

@ -19,18 +19,12 @@ import (
)
type TLSConfig string
type ClusterVersion string
const (
NoTLS TLSConfig = ""
AutoTLS TLSConfig = "auto-tls"
ManualTLS TLSConfig = "manual-tls"
CurrentVersion ClusterVersion = ""
MinorityLastVersion ClusterVersion = "minority-last-version"
QuorumLastVersion ClusterVersion = "quorum-last-version"
LastVersion ClusterVersion = "last-version"
TickDuration = 10 * time.Millisecond
)
@ -43,11 +37,11 @@ type ClusterConfig struct {
AuthToken string
SnapshotCount int
E2eConfig *E2eClusterConfig
}
type E2eClusterConfig struct {
Version ClusterVersion
// ClusterContext is used by "e2e" or "integration" to extend the
// ClusterConfig. The common test cases shouldn't care about what
// data is encoded or included; instead "e2e" or "integration"
// framework should decode or parse it separately.
ClusterContext any
}
func DefaultClusterConfig() ClusterConfig {

View File

@ -138,7 +138,7 @@ type EtcdProcessCluster struct {
type EtcdProcessClusterConfig struct {
Logger *zap.Logger
Version config.ClusterVersion
Version ClusterVersion
DataDirPath string
KeepDataDir bool
EnvVars map[string]string
@ -399,21 +399,21 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
var execPath string
switch cfg.Version {
case config.CurrentVersion:
case CurrentVersion:
execPath = BinPath.Etcd
case config.MinorityLastVersion:
case MinorityLastVersion:
if i <= cfg.ClusterSize/2 {
execPath = BinPath.Etcd
} else {
execPath = BinPath.EtcdLastRelease
}
case config.QuorumLastVersion:
case QuorumLastVersion:
if i <= cfg.ClusterSize/2 {
execPath = BinPath.EtcdLastRelease
} else {
execPath = BinPath.Etcd
}
case config.LastVersion:
case LastVersion:
execPath = BinPath.EtcdLastRelease
default:
panic(fmt.Sprintf("Unknown cluster version %v", cfg.Version))

View File

@ -0,0 +1,28 @@
// Copyright 2022 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package e2e
type ClusterVersion string
const (
CurrentVersion ClusterVersion = ""
MinorityLastVersion ClusterVersion = "minority-last-version"
QuorumLastVersion ClusterVersion = "quorum-last-version"
LastVersion ClusterVersion = "last-version"
)
type ClusterContext struct {
Version ClusterVersion
}

View File

@ -56,9 +56,12 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
AuthTokenOpts: cfg.AuthToken,
SnapshotCount: cfg.SnapshotCount,
}
if cfg.E2eConfig != nil {
e2eConfig.Version = cfg.E2eConfig.Version
if cfg.ClusterContext != nil {
e2eClusterCtx := cfg.ClusterContext.(*ClusterContext)
e2eConfig.Version = e2eClusterCtx.Version
}
switch cfg.ClientTLS {
case config.NoTLS:
e2eConfig.ClientTLS = ClientNonTLS

View File

@ -50,9 +50,7 @@ func (e integrationRunner) BeforeTest(t testing.TB) {
func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) intf.Cluster {
var err error
cfg := config.NewClusterConfig(opts...)
if cfg.E2eConfig != nil {
t.Fatalf("E2e configuration not expected during integration tests, config: %+v", cfg)
}
integrationCfg := ClusterConfig{
Size: cfg.ClusterSize,
QuotaBackendBytes: cfg.QuotaBackendBytes,