From 1756fe60d47bd418675d311c923a8616ec63c602 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 9 Feb 2022 16:34:06 +0100 Subject: [PATCH] integration: custom etcd gracefully termination when running integration tests without an external etcd, the framework spawns an etcd instance executing it in its own process and killing it once the test stops. Instead of killing it directly, allow etcd to exit gracefully or kill it after 5 seconds. --- test/integration/framework/etcd.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/integration/framework/etcd.go b/test/integration/framework/etcd.go index b6fe289f4dc..d83f0fe6703 100644 --- a/test/integration/framework/etcd.go +++ b/test/integration/framework/etcd.go @@ -26,6 +26,7 @@ import ( "os/exec" "runtime" "strings" + "syscall" "time" "google.golang.org/grpc/grpclog" @@ -128,7 +129,18 @@ func RunCustomEtcd(dataDir string, customFlags []string) (url string, stopFn fun cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr stop := func() { - cancel() + // try to exit etcd gracefully + defer cancel() + cmd.Process.Signal(syscall.SIGTERM) + go func() { + select { + case <-ctx.Done(): + klog.Infof("etcd exited gracefully, context cancelled") + case <-time.After(5 * time.Second): + klog.Infof("etcd didn't exit in 5 seconds, killing it") + cancel() + } + }() err := cmd.Wait() klog.Infof("etcd exit status: %v", err) err = os.RemoveAll(etcdDataDir)