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/07 06:56:55 UTC
[incubator-kvrocks] branch unstable updated: refactor: test unit/type/list-2 to Go case (#833)
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 4dc7f77 refactor: test unit/type/list-2 to Go case (#833)
4dc7f77 is described below
commit 4dc7f77c049a1d346cb043dbcac72f457662c729
Author: Sg <su...@users.noreply.github.com>
AuthorDate: Wed Sep 7 14:56:48 2022 +0800
refactor: test unit/type/list-2 to Go case (#833)
Co-authored-by: tison <wa...@gmail.com>
---
.github/workflows/kvrocks.yaml | 2 +-
tests/gocase/go.mod | 2 +
tests/gocase/go.sum | 4 ++
tests/gocase/unit/type/list/list_test.go | 86 ++++++++++++++++++++++++++++++++
tests/gocase/util/server.go | 4 +-
tests/tcl/tests/test_helper.tcl | 1 -
tests/tcl/tests/unit/type/list-2.tcl | 70 --------------------------
7 files changed, 95 insertions(+), 74 deletions(-)
diff --git a/.github/workflows/kvrocks.yaml b/.github/workflows/kvrocks.yaml
index 71aa3be..74f87ae 100644
--- a/.github/workflows/kvrocks.yaml
+++ b/.github/workflows/kvrocks.yaml
@@ -171,7 +171,7 @@ jobs:
export ${{ matrix.runtime_env_vars }}
export KVROCKS_BIN_PATH="$GITHUB_WORKSPACE/build/kvrocks"
export GO_CASE_WORKSPACE="$GITHUB_WORKSPACE/tests/gocase/workspace"
- go test -v ./...
+ go test -v -bench=. ./...
SANITIZER_OUTPUT=$(grep "Sanitizer:" workspace -r || true)
if [[ $SANITIZER_OUTPUT ]]; then
echo "$SANITIZER_OUTPUT"
diff --git a/tests/gocase/go.mod b/tests/gocase/go.mod
index cb7138c..77a79b6 100644
--- a/tests/gocase/go.mod
+++ b/tests/gocase/go.mod
@@ -5,6 +5,7 @@ go 1.19
require (
github.com/go-redis/redis/v9 v9.0.0-beta.2
github.com/stretchr/testify v1.8.0
+ modernc.org/mathutil v1.5.0
)
require (
@@ -12,5 +13,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
diff --git a/tests/gocase/go.sum b/tests/gocase/go.sum
index 8a6efea..5556753 100644
--- a/tests/gocase/go.sum
+++ b/tests/gocase/go.sum
@@ -14,6 +14,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
+github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -28,3 +30,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
+modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
diff --git a/tests/gocase/unit/type/list/list_test.go b/tests/gocase/unit/type/list/list_test.go
new file mode 100644
index 0000000..eb75dd5
--- /dev/null
+++ b/tests/gocase/unit/type/list/list_test.go
@@ -0,0 +1,86 @@
+/*
+ * 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 list
+
+import (
+ "context"
+ "fmt"
+ "math/rand"
+ "strconv"
+ "strings"
+ "testing"
+
+ "github.com/apache/incubator-kvrocks/tests/gocase/util"
+ "github.com/stretchr/testify/require"
+ "modernc.org/mathutil"
+)
+
+// We need a value larger than list-max-ziplist-value to make sure
+// the list has the right encoding when it is swapped in again.
+var largeValue = map[string]string{
+ "zipList": "hello",
+ "linkedList": strings.Repeat("hello", 4),
+}
+
+func BenchmarkLTRIM(b *testing.B) {
+ srv := util.StartServer(b, map[string]string{
+ "list-max-ziplist-size": "4",
+ })
+ defer srv.Close()
+ ctx := context.Background()
+ rdb := srv.NewClient()
+ defer func() { require.NoError(b, rdb.Close()) }()
+
+ key := "myList"
+ startLen := int64(32)
+
+ rand.Seed(0)
+ for typ, value := range largeValue {
+ b.Run(fmt.Sprintf("LTRIM stress testing - %s", typ), func(b *testing.B) {
+ var myList []string
+ require.NoError(b, rdb.Del(ctx, key).Err())
+ require.NoError(b, rdb.RPush(ctx, key, value).Err())
+ myList = append(myList, value)
+
+ for i := int64(0); i < startLen; i++ {
+ s := strconv.FormatInt(rand.Int63(), 10)
+ require.NoError(b, rdb.RPush(ctx, key, s).Err())
+ myList = append(myList, s)
+ }
+
+ for i := 0; i < 1000; i++ {
+ lo := int64(rand.Float64() * float64(startLen))
+ hi := int64(float64(lo) + rand.Float64()*float64(startLen))
+
+ myList = myList[lo:mathutil.Min(int(hi+1), len(myList))]
+ require.NoError(b, rdb.LTrim(ctx, key, lo, hi).Err())
+ require.Equal(b, myList, rdb.LRange(ctx, key, 0, -1).Val(), "failed trim")
+
+ starting := rdb.LLen(ctx, key).Val()
+ for j := starting; j < startLen; j++ {
+ s := strconv.FormatInt(rand.Int63(), 10)
+ require.NoError(b, rdb.RPush(ctx, key, s).Err())
+ myList = append(myList, s)
+ require.Equal(b, myList, rdb.LRange(ctx, key, 0, -1).Val(), "failed append match")
+ }
+ }
+ })
+ }
+}
diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go
index a2ce842..59d8b73 100644
--- a/tests/gocase/util/server.go
+++ b/tests/gocase/util/server.go
@@ -34,7 +34,7 @@ import (
)
type KvrocksServer struct {
- t *testing.T
+ t testing.TB
cmd *exec.Cmd
addr net.Addr
@@ -57,7 +57,7 @@ func (s *KvrocksServer) Close() {
s.clean()
}
-func StartServer(t *testing.T, configs map[string]string) *KvrocksServer {
+func StartServer(t testing.TB, configs map[string]string) *KvrocksServer {
b := os.Getenv("KVROCKS_BIN_PATH")
cmd := exec.Command(b)
diff --git a/tests/tcl/tests/test_helper.tcl b/tests/tcl/tests/test_helper.tcl
index 8fa937d..76c9c5d 100644
--- a/tests/tcl/tests/test_helper.tcl
+++ b/tests/tcl/tests/test_helper.tcl
@@ -38,7 +38,6 @@ set ::all_tests {
unit/type/string
unit/type/incr
unit/type/list
- unit/type/list-2
unit/type/list-3
unit/type/set
unit/type/zset
diff --git a/tests/tcl/tests/unit/type/list-2.tcl b/tests/tcl/tests/unit/type/list-2.tcl
deleted file mode 100644
index 493d5da..0000000
--- a/tests/tcl/tests/unit/type/list-2.tcl
+++ /dev/null
@@ -1,70 +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/type/list-2.tcl
-
-start_server {
- tags {"list"}
- overrides {
- "list-max-ziplist-size" 4
- }
-} {
- source "tests/unit/type/list-common.tcl"
-
- foreach {type large} [array get largevalue] {
- tags {"slow"} {
- test "LTRIM stress testing - $type" {
- set mylist {}
- set startlen 32
- r del mylist
-
- # Start with the large value to ensure the
- # right encoding is used.
- r rpush mylist $large
- lappend mylist $large
-
- for {set i 0} {$i < $startlen} {incr i} {
- set str [randomInt 9223372036854775807]
- r rpush mylist $str
- lappend mylist $str
- }
-
- for {set i 0} {$i < 1000} {incr i} {
- set min [expr {int(rand()*$startlen)}]
- set max [expr {$min+int(rand()*$startlen)}]
- set before_len [llength $mylist]
- set before_len_r [r llen mylist]
- set mylist [lrange $mylist $min $max]
- r ltrim mylist $min $max
- assert_equal $mylist [r lrange mylist 0 -1] "failed trim"
-
- set starting [r llen mylist]
- for {set j [r llen mylist]} {$j < $startlen} {incr j} {
- set str [randomInt 9223372036854775807]
- r rpush mylist $str
- lappend mylist $str
- assert_equal $mylist [r lrange mylist 0 -1] "failed append match"
- }
- }
- }
- }
- }
-}