forked from p93542168/wheat-cache
test(lru): test ttl and worker
This commit is contained in:
parent
758f1bfec2
commit
02bd151381
|
@ -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))
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue