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/12 01:59:31 UTC

[incubator-kvrocks] branch unstable updated: harden slow tests (#976)

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 da27a92  harden slow tests (#976)
da27a92 is described below

commit da27a92d36e5aa355ea00c8d4a4a3c4dc5b744b6
Author: tison <wa...@gmail.com>
AuthorDate: Wed Oct 12 09:59:26 2022 +0800

    harden slow tests (#976)
    
    Signed-off-by: tison <wa...@gmail.com>
---
 tests/gocase/unit/expire/expire_test.go        | 61 +++++++++++++-------------
 tests/gocase/unit/type/strings/strings_test.go | 15 +++++--
 2 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/tests/gocase/unit/expire/expire_test.go b/tests/gocase/unit/expire/expire_test.go
index 158a7cb..f4316ba 100644
--- a/tests/gocase/unit/expire/expire_test.go
+++ b/tests/gocase/unit/expire/expire_test.go
@@ -110,52 +110,53 @@ func TestExpire(t *testing.T) {
 	})
 
 	t.Run("EXPIRE precision is now the millisecond", func(t *testing.T) {
-		// This test is very likely to do a false positive if the server is under pressure,
-		// so if it does not work give it a few more chances.
-		a, b := "", ""
 		util.RetryEventually(t, func() bool {
 			require.NoError(t, rdb.Del(ctx, "x").Err())
-			require.NoError(t, rdb.SetEx(ctx, "x", "somevalue", 1*time.Second).Err())
+			require.NoError(t, rdb.SetEx(ctx, "x", "somevalue", time.Second).Err())
 			time.Sleep(900 * time.Millisecond)
-			a = rdb.Get(ctx, "x").Val()
+			a := rdb.Get(ctx, "x").Val()
 			time.Sleep(1100 * time.Millisecond)
-			b = rdb.Get(ctx, "x").Val()
+			b := rdb.Get(ctx, "x").Val()
 			return a == "somevalue" && b == ""
 		}, 3)
-		require.Equal(t, "somevalue", a)
-		require.Equal(t, "", b)
 	})
 
-	t.Run("PEXPIRE/PSETEX/PEXPIREAT can set sub-second expires", func(t *testing.T) {
-		// This test is very likely to do a false positive if the server is under pressure,
-		// so if it does not work give it a few more chances.
-		a, b, c, d, e, f := "", "", "", "", "", ""
+	t.Run("PEXPIRE can set sub-second expires", func(t *testing.T) {
 		util.RetryEventually(t, func() bool {
-			require.NoError(t, rdb.Del(ctx, "x", "y", "z").Err())
-			require.NoError(t, rdb.Set(ctx, "x", "somevalue", 100*time.Millisecond).Err())
-			time.Sleep(80 * time.Millisecond)
-			a = rdb.Get(ctx, "x").Val()
-			time.Sleep(2100 * time.Millisecond)
-			b = rdb.Get(ctx, "x").Val()
-
+			require.NoError(t, rdb.Del(ctx, "x").Err())
 			require.NoError(t, rdb.Set(ctx, "x", "somevalue", 0).Err())
 			require.NoError(t, rdb.PExpire(ctx, "x", 100*time.Millisecond).Err())
-			time.Sleep(80 * time.Millisecond)
-			c = rdb.Get(ctx, "x").Val()
-			time.Sleep(2100 * time.Millisecond)
-			d = rdb.Get(ctx, "x").Val()
+			time.Sleep(50 * time.Millisecond)
+			a := rdb.Get(ctx, "x").Val()
+			time.Sleep(2 * time.Second)
+			b := rdb.Get(ctx, "x").Val()
+			return a == "somevalue" && b == ""
+		}, 3)
+	})
 
+	t.Run("PEXPIREAT can set sub-second expires", func(t *testing.T) {
+		util.RetryEventually(t, func() bool {
+			require.NoError(t, rdb.Del(ctx, "x").Err())
 			require.NoError(t, rdb.Set(ctx, "x", "somevalue", 0).Err())
 			require.NoError(t, rdb.PExpireAt(ctx, "x", time.UnixMilli(time.Now().Unix()*1000+100)).Err())
-			time.Sleep(80 * time.Millisecond)
-			e = rdb.Get(ctx, "x").Val()
-			time.Sleep(2100 * time.Millisecond)
-			f = rdb.Get(ctx, "x").Val()
+			time.Sleep(50 * time.Millisecond)
+			a := rdb.Get(ctx, "x").Val()
+			time.Sleep(2 * time.Second)
+			b := rdb.Get(ctx, "x").Val()
+			return a == "somevalue" && b == ""
+		}, 3)
+	})
 
-			return a == "somevalue" && b == "" && c == "somevalue" && d == "" && e == "somevalue" && f == ""
+	t.Run("PSETEX can set sub-second expires", func(t *testing.T) {
+		util.RetryEventually(t, func() bool {
+			require.NoError(t, rdb.Del(ctx, "x").Err())
+			require.NoError(t, rdb.Set(ctx, "x", "somevalue", 100*time.Millisecond).Err())
+			time.Sleep(50 * time.Millisecond)
+			a := rdb.Get(ctx, "x").Val()
+			time.Sleep(2 * time.Second)
+			b := rdb.Get(ctx, "x").Val()
+			return a == "somevalue" && b == ""
 		}, 3)
-		require.Equal(t, "somevalue", a)
-		require.Equal(t, "", b)
 	})
 
 	t.Run("TTL returns time to live in seconds", func(t *testing.T) {
diff --git a/tests/gocase/unit/type/strings/strings_test.go b/tests/gocase/unit/type/strings/strings_test.go
index afd096d..cd231ff 100644
--- a/tests/gocase/unit/type/strings/strings_test.go
+++ b/tests/gocase/unit/type/strings/strings_test.go
@@ -21,6 +21,7 @@ package strings
 
 import (
 	"context"
+	"math"
 	"strconv"
 	"strings"
 	"testing"
@@ -35,9 +36,7 @@ func TestString(t *testing.T) {
 	srv := util.StartServer(t, map[string]string{})
 	defer srv.Close()
 	ctx := context.Background()
-	rdb := srv.NewClientWithOption(&redis.Options{
-		ReadTimeout: 10 * time.Second,
-	})
+	rdb := srv.NewClient()
 	defer func() { require.NoError(t, rdb.Close()) }()
 
 	t.Run("SET and GET an item", func(t *testing.T) {
@@ -240,9 +239,17 @@ func TestString(t *testing.T) {
 	})
 
 	t.Run("SETBIT/GETBIT/BITCOUNT/BITPOS boundary check (type string)", func(t *testing.T) {
+		// When setting the last possible bit (offset equal to 2^32 -1) and the string value stored at key
+		// does not yet hold a string value, or holds a small string value, Kvrocks needs to allocate all
+		// intermediate memory which can block the server for some time. See also https://redis.io/commands/setbit/.
+		rdb := srv.NewClientWithOption(&redis.Options{
+			ReadTimeout: time.Minute,
+		})
+		defer func() { require.NoError(t, rdb.Close()) }()
+
 		require.NoError(t, rdb.Del(ctx, "mykey").Err())
 		require.NoError(t, rdb.Set(ctx, "mykey", "", 0).Err())
-		var maxOffset int64 = 4*1024*1024*1024 - 1
+		var maxOffset int64 = math.MaxInt32
 		require.NoError(t, rdb.SetBit(ctx, "mykey", maxOffset, 1).Err())
 		require.EqualValues(t, 1, rdb.GetBit(ctx, "mykey", maxOffset).Val())
 		require.EqualValues(t, 1, rdb.BitCount(ctx, "mykey", &redis.BitCount{Start: 0, End: maxOffset / 8}).Val())