diff --git a/command_test.go b/command_test.go index cc7d098..bd1227d 100644 --- a/command_test.go +++ b/command_test.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/alicebob/miniredis/v2" "math/rand/v2" "os" "sync" @@ -32,22 +33,33 @@ func startup() { const ( testTypeRotom = "rotom" + testTypeMiniRedis = "miniRedis" testTypeRealRedis = "realRedis" ) func TestCommand(t *testing.T) { - t.Run(testTypeRealRedis, func(t *testing.T) { - // NOTES: run redis first! + t.Run(testTypeMiniRedis, func(t *testing.T) { + s := miniredis.RunT(t) rdb := redis.NewClient(&redis.Options{ - Addr: ":6379", + Addr: s.Addr(), }) sleepFn := func(dur time.Duration) { - time.Sleep(dur) + s.FastForward(dur) } - rdb.FlushDB(context.Background()) - testCommand(t, testTypeRealRedis, rdb, sleepFn) - rdb.FlushDB(context.Background()) + testCommand(t, testTypeMiniRedis, rdb, sleepFn) }) + //t.Run(testTypeRealRedis, func(t *testing.T) { + // // NOTES: run redis first! + // rdb := redis.NewClient(&redis.Options{ + // Addr: ":6379", + // }) + // sleepFn := func(dur time.Duration) { + // time.Sleep(dur) + // } + // rdb.FlushDB(context.Background()) + // testCommand(t, testTypeRealRedis, rdb, sleepFn) + // rdb.FlushDB(context.Background()) + //}) t.Run(testTypeRotom, func(t *testing.T) { go startup() time.Sleep(time.Second / 2) diff --git a/go.mod b/go.mod index 0e963f5..f39bc91 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,8 @@ require ( ) require ( + github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect + github.com/alicebob/miniredis/v2 v2.33.0 // indirect github.com/bytedance/sonic/loader v0.2.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect diff --git a/go.sum b/go.sum index a991357..1ce8549 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,9 @@ github.com/aclements/go-perfevent v0.0.0-20240301234650-f7843625020f h1:JjxwchlOepwsUWcQwD2mLUAGE9aCp0/ehy6yCHFBOvo= github.com/aclements/go-perfevent v0.0.0-20240301234650-f7843625020f/go.mod h1:tMDTce/yLLN/SK8gMOxQfnyeMeCg8KGzp0D1cbECEeo= +github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= +github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= +github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA= +github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=