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/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new e1781d1d fix: data dace when closing the server close in Go tests
(#1669)
e1781d1d is described below
commit e1781d1d1dbe488e7c007d88d4f70803b257569a
Author: hulk <[email protected]>
AuthorDate: Sat Aug 12 00:45:41 2023 +0800
fix: data dace when closing the server close in Go tests (#1669)
---
tests/gocase/util/server.go | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go
index 00a90350..995d0e6b 100644
--- a/tests/gocase/util/server.go
+++ b/tests/gocase/util/server.go
@@ -28,6 +28,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
+ "sync"
"syscall"
"testing"
"time"
@@ -104,11 +105,27 @@ func (s *KvrocksServer) Close() {
func (s *KvrocksServer) close(keepDir bool) {
require.NoError(s.t, s.cmd.Process.Signal(syscall.SIGTERM))
f := func(err error) { require.NoError(s.t, err) }
+
+ var wg sync.WaitGroup
timer := time.AfterFunc(defaultGracePeriod, func() {
+ defer wg.Done()
+ wg.Add(1)
+
require.NoError(s.t, s.cmd.Process.Kill())
- f = func(err error) { require.EqualError(s.t, err, "signal:
killed") }
+ f = func(err error) {
+ // The process may have already exited, so we can't use
`require.NoError` here.
+ if err != nil {
+ require.EqualError(s.t, err, "signal: killed")
+ }
+ }
})
- defer timer.Stop()
+
+ defer func() {
+ _ = timer.Stop()
+ // Stop function won't wait for the timer routine if it's
already expired,
+ // so we need to wait for it here to prevent panic.
+ wg.Wait()
+ }()
f(s.cmd.Wait())
s.clean(keepDir)
}