diff --git a/tests/gocase/unit/type/incr/incr_test.go b/tests/gocase/unit/type/incr/incr_test.go index f8a1785cfb1..3b507ff5be9 100644 --- a/tests/gocase/unit/type/incr/incr_test.go +++ b/tests/gocase/unit/type/incr/incr_test.go @@ -22,6 +22,7 @@ package incr import ( "context" "testing" + "time" "github.com/apache/kvrocks/tests/gocase/util" "github.com/stretchr/testify/require" @@ -75,6 +76,14 @@ func testIncr(t *testing.T, configs util.KvrocksServerConfigs) { require.EqualValues(t, 34359738368, rdb.IncrBy(ctx, "novar", 17179869184).Val()) }) + t.Run("INCR over an expired key", func(t *testing.T) { + require.NoError(t, rdb.SetEx(ctx, "expired-foo", "1024", 2*time.Second).Err()) + require.NoError(t, rdb.SetEx(ctx, "expired-str", "value", 2*time.Second).Err()) + time.Sleep(3 * time.Second) + require.EqualValues(t, 1, rdb.IncrBy(ctx, "expired-foo", 1).Val()) + require.EqualValues(t, 1, rdb.IncrBy(ctx, "expired-str", 1).Val()) + }) + t.Run("INCR fails against key with spaces (left)", func(t *testing.T) { require.NoError(t, rdb.Set(ctx, "novar", " 11", 0).Err()) util.ErrorRegexp(t, rdb.Incr(ctx, "novar").Err(), "ERR.*") @@ -133,6 +142,12 @@ func testIncr(t *testing.T, configs util.KvrocksServerConfigs) { require.EqualValues(t, 34359738368, rdb.IncrByFloat(ctx, "novar", 17179869184).Val()) }) + t.Run("INCRBYFLOAT over an expired key", func(t *testing.T) { + require.NoError(t, rdb.SetEx(ctx, "expired-foo", "10.24", 2*time.Second).Err()) + time.Sleep(3 * time.Second) + require.EqualValues(t, 1, rdb.IncrBy(ctx, "expired-foo", 1.0).Val()) + }) + t.Run("INCRBYFLOAT fails against key with spaces (left)", func(t *testing.T) { require.NoError(t, rdb.Set(ctx, "novar", " 11", 0).Err()) util.ErrorRegexp(t, rdb.IncrByFloat(ctx, "novar", 1.0).Err(), "ERR.*valid.*")