diff --git a/core/stores/cache/cleaner_test.go b/core/stores/cache/cleaner_test.go new file mode 100644 index 00000000..b4e69a60 --- /dev/null +++ b/core/stores/cache/cleaner_test.go @@ -0,0 +1,56 @@ +package cache + +import ( + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +func TestNextDelay(t *testing.T) { + tests := []struct { + name string + input time.Duration + output time.Duration + ok bool + }{ + { + name: "second", + input: time.Second, + output: time.Second * 5, + ok: true, + }, + { + name: "5 seconds", + input: time.Second * 5, + output: time.Minute, + ok: true, + }, + { + name: "minute", + input: time.Minute, + output: time.Minute * 5, + ok: true, + }, + { + name: "5 minutes", + input: time.Minute * 5, + output: time.Hour, + ok: true, + }, + { + name: "hour", + input: time.Hour, + output: 0, + ok: false, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + next, ok := nextDelay(test.input) + assert.Equal(t, test.ok, ok) + assert.Equal(t, test.output, next) + }) + } +} diff --git a/core/stores/sqlc/cachedsql_test.go b/core/stores/sqlc/cachedsql_test.go index 5e11128a..534e99ca 100644 --- a/core/stores/sqlc/cachedsql_test.go +++ b/core/stores/sqlc/cachedsql_test.go @@ -193,13 +193,16 @@ func TestCachedConn_QueryRowIndex_HasCache_IntPrimary(t *testing.T) { }, } + s, err := miniredis.Run() + if err != nil { + t.Error(err) + } + defer s.Close() + for _, test := range tests { t.Run(test.name, func(t *testing.T) { resetStats() - s, err := miniredis.Run() - if err != nil { - t.Error(err) - } + s.FlushAll() r := redis.NewRedis(s.Addr(), redis.NodeType) c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10), @@ -242,6 +245,8 @@ func TestCachedConn_QueryRowIndex_HasWrongCache(t *testing.T) { if err != nil { t.Error(err) } + s.FlushAll() + defer s.Close() r := redis.NewRedis(s.Addr(), redis.NodeType) c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),