feat(test): update lru test
This commit is contained in:
parent
404dc1fbbc
commit
b6348f5992
|
@ -61,7 +61,7 @@ func TestNewLRUCache2(t *testing.T) {
|
|||
|
||||
func TestLruProcess(t *testing.T) {
|
||||
lru := NewLRUCache()
|
||||
lru.clearSize = 1000
|
||||
lru.clearSize = 3600
|
||||
|
||||
for i := 100; i < 200; i++ {
|
||||
lru.Add(&proto.BaseKey{
|
||||
|
@ -78,16 +78,17 @@ func TestLruProcess(t *testing.T) {
|
|||
}, stringx.NewStringSingle())
|
||||
}
|
||||
|
||||
require.Equal(t, lru.nowSize, int64(200*8))
|
||||
require.Equal(t, lru.nowSize, int64(200*24))
|
||||
|
||||
// 自动清理测试
|
||||
fmt.Println(lru.clearSize)
|
||||
require.Equal(t, lru.li.Len(), 200)
|
||||
time.Sleep(3 * time.Second)
|
||||
fmt.Println(lru.nowSize)
|
||||
require.Less(t, lru.nowSize, lru.clearSize+1)
|
||||
|
||||
// TTL 测试
|
||||
// TTL 测试, 100-200 key 发生自动清理 留下 50-100 共 100(0-100) + 20个 key,5s 后,前 0-100的 key 过期,剩下
|
||||
time.Sleep(2 * time.Second)
|
||||
require.Equal(t, lru.li.Len(), 25)
|
||||
require.Equal(t, lru.li.Len(), 50)
|
||||
|
||||
// 过期全部的 Key
|
||||
for i := 100; i < 200; i++ {
|
||||
|
|
|
@ -28,9 +28,9 @@ func Test_LruTTl(t *testing.T) {
|
|||
Key: "990",
|
||||
Ttl: 10,
|
||||
}, s)
|
||||
require.Equal(t, lru.nowSize, int64(16))
|
||||
require.Equal(t, lru.nowSize, int64(48))
|
||||
|
||||
time.Sleep(4 * time.Second)
|
||||
require.Equal(t, lru.nowSize, int64(8))
|
||||
require.Equal(t, lru.nowSize, int64(24))
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ func TestWorker(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
lru := NewLRUCache()
|
||||
produce := event.NewProduce(lru.GetDriver())
|
||||
workEvent := event.NewEvent(OptionEventName)
|
||||
workEvent := produce.NewEvent(OptionEventName)
|
||||
workEvent.SetValue(WorkFuncEventKey, event.EventWorkFunc(func() (interface{}, error) {
|
||||
v1 := stringx.NewStringSingle()
|
||||
key := proto.BaseKey{
|
||||
|
@ -39,7 +39,7 @@ func TestSingleCache_DelToClearSize(t *testing.T) {
|
|||
produce := event.NewProduce(lru.GetDriver())
|
||||
|
||||
for i := int32(20000); i >= 1; i-- {
|
||||
workEvent := event.NewEvent(OptionEventName)
|
||||
workEvent := produce.NewEvent(OptionEventName)
|
||||
workEvent.SetValue(WorkFuncEventKey, event.EventWorkFunc(func() (interface{}, error) {
|
||||
v1 := stringx.NewStringSingle()
|
||||
key := proto.BaseKey{
|
||||
|
@ -52,6 +52,7 @@ func TestSingleCache_DelToClearSize(t *testing.T) {
|
|||
workEvent.InitWaitEvent()
|
||||
produce.Call(ctx, workEvent)
|
||||
workEvent.StartWaitEvent(2 * time.Second)
|
||||
produce.Recovery(workEvent)
|
||||
}
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
|
Loading…
Reference in New Issue