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/19 06:37:40 UTC
[incubator-kvrocks] branch unstable updated: Move TCL test unit/quit to Go case (#871)
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 ca2a496 Move TCL test unit/quit to Go case (#871)
ca2a496 is described below
commit ca2a496505b9a0dc0542d6d4674116a4f39f2056
Author: IoCing <39...@users.noreply.github.com>
AuthorDate: Mon Sep 19 14:37:35 2022 +0800
Move TCL test unit/quit to Go case (#871)
This closes #857.
Co-authored-by: hulk <hu...@gmail.com>
Co-authored-by: Ruixiang Tan <81...@qq.com>
Co-authored-by: Twice <tw...@gmail.com>
---
tests/gocase/unit/quit_test.go | 88 +++++++++++++++++++++++++++++++++++++++++
tests/tcl/tests/test_helper.tcl | 1 -
tests/tcl/tests/unit/quit.tcl | 63 -----------------------------
3 files changed, 88 insertions(+), 64 deletions(-)
diff --git a/tests/gocase/unit/quit_test.go b/tests/gocase/unit/quit_test.go
new file mode 100644
index 0000000..cc70e7c
--- /dev/null
+++ b/tests/gocase/unit/quit_test.go
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package quit
+
+import (
+ "context"
+ "strings"
+ "testing"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/go-redis/redis/v9"
+ "github.com/stretchr/testify/require"
+)
+
+func reconnect(srv *util.KvrocksServer, rdb **redis.Client) error {
+ if err := (*rdb).Close(); err != nil {
+ return err
+ }
+ *rdb = srv.NewClient()
+ return nil
+}
+
+func TestPipeQuit(t *testing.T) {
+ srv := util.StartServer(t, map[string]string{})
+ defer srv.Close()
+ rdb := srv.NewClient()
+ ctx := context.Background()
+
+ t.Run("QUIT returns OK", func(t *testing.T) {
+ trdb := srv.NewTCPClient()
+ require.NoError(t, trdb.Write("*1\r\n$4\r\nquit\r\n"))
+ resQuit, errQuit := trdb.ReadLine()
+ require.Equal(t, "+OK", resQuit)
+ require.NoError(t, errQuit)
+ require.NoError(t, trdb.Write("*1\r\n$4\r\nping\r\n"))
+ resPing, errPing := trdb.ReadLine()
+ require.Equal(t, "", resPing)
+ require.Error(t, errPing)
+ require.NoError(t, trdb.Close())
+ })
+
+ t.Run("Pipelined commands after QUIT must not be executed", func(t *testing.T) {
+ require.NoError(t, reconnect(srv, &rdb))
+ pipe := rdb.Pipeline()
+ cmd1 := pipe.Do(ctx, "quit")
+ cmd2 := pipe.Do(ctx, "set", "foo", "bar")
+ _, err := pipe.Exec(ctx)
+ require.Equal(t, "OK", cmd1.Val())
+ require.Equal(t, nil, cmd2.Val())
+ require.Error(t, err)
+ require.NoError(t, reconnect(srv, &rdb))
+ cmd3 := rdb.Get(ctx, "foo")
+ require.Equal(t, "", cmd3.Val())
+ })
+
+ t.Run("Pipelined commands after QUIT that exceed read buffer size", func(t *testing.T) {
+ require.NoError(t, reconnect(srv, &rdb))
+ pipe := rdb.Pipeline()
+ cmd1 := pipe.Do(ctx, "quit")
+ cmd2 := pipe.Do(ctx, "set", "foo", strings.Repeat("x", 1024))
+ _, err := pipe.Exec(ctx)
+ require.Equal(t, "OK", cmd1.Val())
+ require.Equal(t, nil, cmd2.Val())
+ require.Error(t, err)
+ require.NoError(t, reconnect(srv, &rdb))
+ cmd3 := rdb.Get(ctx, "foo")
+ require.Equal(t, "", cmd3.Val())
+ })
+
+ require.NoError(t, rdb.Close())
+}
diff --git a/tests/tcl/tests/test_helper.tcl b/tests/tcl/tests/test_helper.tcl
index 17629ce..895eb72 100644
--- a/tests/tcl/tests/test_helper.tcl
+++ b/tests/tcl/tests/test_helper.tcl
@@ -42,7 +42,6 @@ set ::all_tests {
unit/type/stream
unit/multi
unit/expire
- unit/quit
unit/slowlog
unit/pubsub
unit/introspection
diff --git a/tests/tcl/tests/unit/quit.tcl b/tests/tcl/tests/unit/quit.tcl
deleted file mode 100644
index 4bb6132..0000000
--- a/tests/tcl/tests/unit/quit.tcl
+++ /dev/null
@@ -1,63 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-# Copyright (c) 2006-2020, Salvatore Sanfilippo
-# See bundled license file licenses/LICENSE.redis for details.
-
-# This file is copied and modified from the Redis project,
-# which started out as: https://github.com/redis/redis/blob/dbcc0a8/tests/unit/quit.tcl
-
-start_server {tags {"quit"}} {
- proc format_command {args} {
- set cmd "*[llength $args]\r\n"
- foreach a $args {
- append cmd "$[string length $a]\r\n$a\r\n"
- }
- set _ $cmd
- }
-
- test "QUIT returns OK" {
- reconnect
- assert_equal OK [r quit]
- assert_error * {r ping}
- }
-
- test "Pipelined commands after QUIT must not be executed" {
- reconnect
- r write [format_command quit]
- r write [format_command set foo bar]
- r flush
- assert_equal OK [r read]
- assert_error * {r read}
-
- reconnect
- assert_equal {} [r get foo]
- }
-
- test "Pipelined commands after QUIT that exceed read buffer size" {
- reconnect
- r write [format_command quit]
- r write [format_command set foo [string repeat "x" 1024]]
- r flush
- assert_equal OK [r read]
- assert_error * {r read}
-
- reconnect
- assert_equal {} [r get foo]
-
- }
-}