Skip to content

Commit

Permalink
tests/common: kill etcd cluster processes after test finished only af…
Browse files Browse the repository at this point in the history
…ter peerTLS is turned on

Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Apr 11, 2023
1 parent ddcba83 commit 166bd13
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/common/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func e2eClusterTestCases() []testCase {
},
{
name: "PeerTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS, ClusterContext: &e2e.ClusterContext{ForceStop: true}},
},
{
name: "PeerAutoTLS",
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS, ClusterContext: &e2e.ClusterContext{ForceStop: true}},
},
{
name: "ClientTLS",
Expand Down
21 changes: 17 additions & 4 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ type EtcdProcessCluster struct {
}

type EtcdProcessClusterConfig struct {
Logger *zap.Logger
Version ClusterVersion
Logger *zap.Logger
Version ClusterVersion
ForceStop bool
// DataDirPath specifies the data-dir for the members. If test cases
// do not specify `DataDirPath`, then e2e framework creates a
// temporary directory for each member; otherwise, it creates a
Expand Down Expand Up @@ -886,9 +887,14 @@ func (epc *EtcdProcessCluster) Etcdctl(opts ...config.ClientOption) *EtcdctlV3 {
return etcdctl
}

func (epc *EtcdProcessCluster) Close() error {
func (epc *EtcdProcessCluster) Close() (err error) {
epc.lg.Info("closing test cluster...")
err := epc.Stop()
if epc.Cfg.ForceStop {
err = epc.ForceStop()
} else {
err = epc.Stop()
}

for _, p := range epc.Procs {
// p is nil when NewEtcdProcess fails in the middle
// Close still gets called to clean up test data
Expand All @@ -903,6 +909,13 @@ func (epc *EtcdProcessCluster) Close() error {
return err
}

func (epc *EtcdProcessCluster) ForceStop() (err error) {
for _, member := range epc.Procs {
member.Kill()
}
return epc.Stop()
}

func findMemberIDByEndpoint(members []*etcdserverpb.Member, endpoint string) (uint64, error) {
for _, m := range members {
if m.ClientURLs[0] == endpoint {
Expand Down
3 changes: 2 additions & 1 deletion tests/framework/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ const (
)

type ClusterContext struct {
Version ClusterVersion
Version ClusterVersion
ForceStop bool
}
1 change: 1 addition & 0 deletions tests/framework/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
if cfg.ClusterContext != nil {
e2eClusterCtx := cfg.ClusterContext.(*ClusterContext)
e2eConfig.Version = e2eClusterCtx.Version
e2eConfig.ForceStop = e2eClusterCtx.ForceStop
}

switch cfg.ClientTLS {
Expand Down

0 comments on commit 166bd13

Please sign in to comment.