diff --git a/pkg/lru/ttl_test.go b/pkg/lru/ttl_test.go new file mode 100644 index 0000000..eecfcd6 --- /dev/null +++ b/pkg/lru/ttl_test.go @@ -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)) + +} diff --git a/pkg/lru/woker_test.go b/pkg/lru/woker_test.go index 9e8a21b..52ad96d 100644 --- a/pkg/lru/woker_test.go +++ b/pkg/lru/woker_test.go @@ -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) }