Skip to content

Commit

Permalink
fix(tests): add test cases for INCRBY over expired keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
FishYoung committed Nov 18, 2024
1 parent e5a856d commit 5ea8d17
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/gocase/unit/type/incr/incr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package incr
import (
"context"
"testing"
"time"

"github.com/apache/kvrocks/tests/gocase/util"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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.*")
Expand Down Expand Up @@ -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.*")
Expand Down

0 comments on commit 5ea8d17

Please sign in to comment.