mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 08:48:40 +08:00
add more tests
This commit is contained in:
parent
5a4afb1518
commit
e37858295a
56
core/stores/cache/cleaner_test.go
vendored
Normal file
56
core/stores/cache/cleaner_test.go
vendored
Normal file
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -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 {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
resetStats()
|
resetStats()
|
||||||
s, err := miniredis.Run()
|
s.FlushAll()
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
||||||
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
||||||
@ -242,6 +245,8 @@ func TestCachedConn_QueryRowIndex_HasWrongCache(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
s.FlushAll()
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
r := redis.NewRedis(s.Addr(), redis.NodeType)
|
||||||
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
c := NewNodeConn(dummySqlConn{}, r, cache.WithExpiry(time.Second*10),
|
||||||
|
Loading…
Reference in New Issue
Block a user