Skip to content

Commit

Permalink
tests/framework/e2e: kill etcd cluster processes after test finished
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Apr 4, 2023
1 parent 6f4e5f3 commit 6c25fac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
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 @@ -878,6 +879,13 @@ func (epc *EtcdProcessCluster) Stop() (err error) {
return err
}

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

func (epc *EtcdProcessCluster) Client(opts ...config.ClientOption) *EtcdctlV3 {
etcdctl, err := NewEtcdctl(epc.Cfg.Client, epc.EndpointsGRPC(), opts...)
if err != nil {
Expand All @@ -886,9 +894,14 @@ func (epc *EtcdProcessCluster) Client(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 Down
4 changes: 4 additions & 0 deletions tests/framework/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
e2eConfig.Version = e2eClusterCtx.Version
}

if e2eConfig.ClusterSize == 3 {
e2eConfig.ForceStop = true
}

switch cfg.ClientTLS {
case config.NoTLS:
e2eConfig.Client.ConnectionType = ClientNonTLS
Expand Down

0 comments on commit 6c25fac

Please sign in to comment.