test(lru): test ttl and worker

This commit is contained in:
bandl 2021-10-12 15:11:49 +08:00
parent 758f1bfec2
commit 02bd151381
2 changed files with 36 additions and 1 deletions

35
pkg/lru/ttl_test.go Normal file
View File

@ -0,0 +1,35 @@
package lru
import (
"fmt"
"gitee.com/timedb/wheatCache/pkg/proto"
"gitee.com/timedb/wheatCache/pkg/structure/stringx"
"github.com/stretchr/testify/require"
"testing"
"time"
)
func TestTTlCup(t *testing.T) {
k := make([]string, 100, 3000)
fmt.Println(cap(k))
p := k[:50]
fmt.Println(cap(p))
}
func Test_LruTTl(t *testing.T) {
lru := NewLRUCache()
s := stringx.NewStringSingle()
lru.Add(&proto.BaseKey{
Key: "k8s",
Ttl: 1,
}, s)
lru.Add(&proto.BaseKey{
Key: "990",
Ttl: 10,
}, s)
require.Equal(t, lru.nowSize, int64(16))
time.Sleep(4 * time.Second)
require.Equal(t, lru.nowSize, int64(8))
}

View File

@ -53,6 +53,6 @@ func TestSingleCache_DelToClearSize(t *testing.T) {
workEvent.StartWaitEvent(2 * time.Second)
}
time.Sleep(5 * time.Second)
time.Sleep(5<<10 * time.Second)
logx.Info("end size is %d", lru.nowSize)
}