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/11 12:12:22 UTC

[incubator-kvrocks] branch unstable updated: Move TCL test unit/limits to Go case (#854)

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 2ebd603  Move TCL test unit/limits to Go case (#854)
2ebd603 is described below

commit 2ebd603aa5772f31ab1e9cb8ca04a058cbb2df2a
Author: tison <wa...@gmail.com>
AuthorDate: Sun Sep 11 20:12:17 2022 +0800

    Move TCL test unit/limits to Go case (#854)
    
    Signed-off-by: tison <wa...@gmail.com>
---
 .../assertions.go => unit/limits/limits_test.go}   | 37 ++++++++++++++++--
 tests/gocase/util/assertions.go                    |  2 +-
 tests/tcl/tests/test_helper.tcl                    |  1 -
 tests/tcl/tests/unit/limits.tcl                    | 44 ----------------------
 4 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/tests/gocase/util/assertions.go b/tests/gocase/unit/limits/limits_test.go
similarity index 50%
copy from tests/gocase/util/assertions.go
copy to tests/gocase/unit/limits/limits_test.go
index 3e6f9a1..a1a8b82 100644
--- a/tests/gocase/util/assertions.go
+++ b/tests/gocase/unit/limits/limits_test.go
@@ -17,15 +17,44 @@
  * under the License.
  */
 
-package util
+package limits
 
 import (
+	"strings"
 	"testing"
 
+	"github.com/apache/incubator-kvrocks/tests/gocase/util"
 	"github.com/stretchr/testify/require"
 )
 
-func ErrorRegexp(t testing.TB, err error, rx interface{}, msgAndArgs ...interface{}) {
-	require.Error(t, err, msgAndArgs)
-	require.Regexp(t, rx, err.Error())
+func TestNetworkLimits(t *testing.T) {
+	srv := util.StartServer(t, map[string]string{
+		"maxclients": "10",
+	})
+	defer srv.Close()
+
+	t.Run("check if maxclients works refusing connections", func(t *testing.T) {
+		var clean []func()
+		defer func() {
+			for _, f := range clean {
+				f()
+			}
+		}()
+
+		for i := 0; i < 50; i++ {
+			c := srv.NewTCPClient()
+			clean = append(clean, func() { require.NoError(t, c.Close()) })
+			require.NoError(t, c.Write("*1\r\n$4\r\nPING\r\n"))
+			r, err := c.ReadLine()
+			require.NoError(t, err)
+			if strings.Contains(r, "ERR") {
+				require.Regexp(t, ".*ERR max.*reached.*", r)
+				require.Contains(t, []int{9, 10}, i)
+				return
+			}
+			require.Equal(t, "+PONG", r)
+		}
+
+		require.Fail(t, "maxclients doesn't work refusing connections")
+	})
 }
diff --git a/tests/gocase/util/assertions.go b/tests/gocase/util/assertions.go
index 3e6f9a1..41bc0fe 100644
--- a/tests/gocase/util/assertions.go
+++ b/tests/gocase/util/assertions.go
@@ -27,5 +27,5 @@ import (
 
 func ErrorRegexp(t testing.TB, err error, rx interface{}, msgAndArgs ...interface{}) {
 	require.Error(t, err, msgAndArgs)
-	require.Regexp(t, rx, err.Error())
+	require.Regexp(t, rx, err.Error(), msgAndArgs)
 }
diff --git a/tests/tcl/tests/test_helper.tcl b/tests/tcl/tests/test_helper.tcl
index 82c577b..9bdb682 100644
--- a/tests/tcl/tests/test_helper.tcl
+++ b/tests/tcl/tests/test_helper.tcl
@@ -48,7 +48,6 @@ set ::all_tests {
     unit/slowlog
     unit/pubsub
     unit/introspection
-    unit/limits
     unit/geo
     unit/config
     unit/scripting
diff --git a/tests/tcl/tests/unit/limits.tcl b/tests/tcl/tests/unit/limits.tcl
deleted file mode 100644
index ce15e9c..0000000
--- a/tests/tcl/tests/unit/limits.tcl
+++ /dev/null
@@ -1,44 +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/limits.tcl
-
-start_server {tags {"limits network"} overrides {maxclients 10}} {
-    if {$::tls} {
-        set expected_code "*I/O error*"
-    } else {
-        set expected_code "*ERR max*reached*"
-    }
-    test {Check if maxclients works refusing connections} {
-        set c 0
-        catch {
-            while {$c < 50} {
-                incr c
-                set rd [redis_deferring_client]
-                $rd ping
-                $rd read
-                after 100
-            }
-        } e
-        assert {$c > 8 && $c <= 10}
-        set e
-    } $expected_code
-}