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/10/03 13:08:28 UTC

[incubator-kvrocks] branch unstable updated: refactor: go cases with var flags (#939)

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 e5ea391  refactor: go cases with var flags (#939)
e5ea391 is described below

commit e5ea3911828e336348f139b0612041d277a1c1ef
Author: tison <wa...@gmail.com>
AuthorDate: Mon Oct 3 21:08:22 2022 +0800

    refactor: go cases with var flags (#939)
    
    Signed-off-by: tison <wa...@gmail.com>
---
 tests/gocase/util/server.go | 16 ++++++++++++----
 x.py                        | 17 +++++++++--------
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go
index 2aa3d37..8da2ae4 100644
--- a/tests/gocase/util/server.go
+++ b/tests/gocase/util/server.go
@@ -21,6 +21,7 @@ package util
 
 import (
 	"context"
+	"flag"
 	"fmt"
 	"net"
 	"os"
@@ -34,6 +35,10 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
+var binPath = flag.String("binPath", "", "directory including kvrocks build files")
+var workspace = flag.String("workspace", "", "directory of cases workspace")
+var deleteOnExit = flag.Bool("deleteOnExit", false, "whether to delete workspace on exit")
+
 type KvrocksServer struct {
 	t    testing.TB
 	cmd  *exec.Cmd
@@ -78,8 +83,8 @@ func (s *KvrocksServer) Close() {
 }
 
 func StartServer(t testing.TB, configs map[string]string) *KvrocksServer {
-	b := os.Getenv("KVROCKS_BIN_PATH")
-	require.NotEmpty(t, b, "please set the environment variable `KVROCKS_BIN_PATH`")
+	b := *binPath
+	require.NotEmpty(t, b, "please set the binary path by `-binPath`")
 	cmd := exec.Command(b)
 
 	addr, err := findFreePort()
@@ -87,8 +92,8 @@ func StartServer(t testing.TB, configs map[string]string) *KvrocksServer {
 	configs["bind"] = addr.IP.String()
 	configs["port"] = fmt.Sprintf("%d", addr.Port)
 
-	dir := os.Getenv("GO_CASE_WORKSPACE")
-	require.NotEmpty(t, dir, "please set the environment variable `GO_CASE_WORKSPACE`")
+	dir := *workspace
+	require.NotEmpty(t, dir, "please set the workspace by `-workspace`")
 	dir, err = os.MkdirTemp(dir, fmt.Sprintf("%s-%d-*", t.Name(), time.Now().UnixMilli()))
 	require.NoError(t, err)
 	configs["dir"] = dir
@@ -127,6 +132,9 @@ func StartServer(t testing.TB, configs map[string]string) *KvrocksServer {
 		clean: func() {
 			require.NoError(t, stdout.Close())
 			require.NoError(t, stderr.Close())
+			if *deleteOnExit {
+				require.NoError(t, os.RemoveAll(dir))
+			}
 		},
 	}
 }
diff --git a/x.py b/x.py
index 3a7f5d5..bd3838c 100755
--- a/x.py
+++ b/x.py
@@ -240,14 +240,15 @@ def test_go(dir: str, rest: List[str]) -> None:
     binpath = Path(dir).absolute() / 'kvrocks'
     basedir = Path(__file__).parent.absolute() / 'tests' / 'gocase'
     worksapce = basedir / 'workspace'
-    goenv = {
-        'KVROCKS_BIN_PATH': str(binpath),
-        'GO_CASE_WORKSPACE': str(worksapce),
-    }
-    goenv = {**os.environ, **goenv}
-    run(go, 'test', '-v', '-bench=.', './...', *rest,
-        env=goenv, cwd=str(basedir), verbose=True
-    )
+
+    args = [
+        'test', '-v', '-bench=.', './...',
+        f'-binPath={binpath}',
+        f'-workspace={worksapce}',
+        *rest
+    ]
+
+    run(go, *args, cwd=str(basedir), verbose=True)
 
 if __name__ == '__main__':
     parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)