You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by ti...@apache.org on 2022/09/24 14:00:42 UTC

[incubator-kvrocks] branch unstable updated: Send SIGTERM after finishing the unit test (#898)

This is an automated email from the ASF dual-hosted git repository.

tison pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 231d48d  Send SIGTERM after finishing the unit test (#898)
231d48d is described below

commit 231d48d5b0129ca0ebb5e070bb769264dd0d0ce5
Author: ColinChamber <95...@users.noreply.github.com>
AuthorDate: Sat Sep 24 22:00:36 2022 +0800

    Send SIGTERM after finishing the unit test (#898)
---
 tests/gocase/util/constants.go | 6 ++++++
 tests/gocase/util/server.go    | 9 +++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tests/gocase/util/constants.go b/tests/gocase/util/constants.go
index cdb8bf4..9788796 100644
--- a/tests/gocase/util/constants.go
+++ b/tests/gocase/util/constants.go
@@ -21,3 +21,9 @@ package util
 
 const DefaultDelta = 0.000001
 const ErrRedisNil = "redis: nil"
+
+// Kubernetes will send a SIGTERM signal to the containers in the pod after deleting the pod.
+// It waits for a specified time, called the termination grace period. By default, this is 30 seconds.
+// If the containers are still running after the grace period,
+// they are sent the SIGKILL signal and forcibly removed.
+const k8sDefaultGracePeriod = 30
diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go
index 10cca14..d6f5285 100644
--- a/tests/gocase/util/server.go
+++ b/tests/gocase/util/server.go
@@ -26,6 +26,7 @@ import (
 	"os"
 	"os/exec"
 	"path/filepath"
+	"syscall"
 	"testing"
 	"time"
 
@@ -67,8 +68,12 @@ func (s *KvrocksServer) NewTCPClient() *tcpClient {
 }
 
 func (s *KvrocksServer) Close() {
-	require.NoError(s.t, s.cmd.Process.Kill())
-	require.EqualError(s.t, s.cmd.Wait(), "signal: killed")
+	require.NoError(s.t, s.cmd.Process.Signal(syscall.SIGTERM))
+	timer := time.AfterFunc(k8sDefaultGracePeriod*time.Second, func() {
+		require.NoError(s.t, s.cmd.Process.Kill())
+	})
+	defer timer.Stop()
+	require.NoError(s.t, s.cmd.Wait())
 	s.clean()
 }