From 95d3fdbd171208e0837bc7e280de9b942ea81f6c Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Mon, 18 Oct 2021 23:58:46 +0800 Subject: [PATCH] test(skiplist, ttl): update ttl --- pkg/lru/ttl_test.go | 5 ++-- pkg/lru/woker_test.go | 7 ++--- pkg/util/skiplist/skiplist_test.go | 41 ++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/pkg/lru/ttl_test.go b/pkg/lru/ttl_test.go index eecfcd6..76b8d15 100644 --- a/pkg/lru/ttl_test.go +++ b/pkg/lru/ttl_test.go @@ -2,11 +2,12 @@ package lru import ( "fmt" + "testing" + "time" + "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) { diff --git a/pkg/lru/woker_test.go b/pkg/lru/woker_test.go index 52ad96d..6009258 100644 --- a/pkg/lru/woker_test.go +++ b/pkg/lru/woker_test.go @@ -2,13 +2,14 @@ package lru import ( "context" + "testing" + "time" + "gitee.com/timedb/wheatCache/pkg/event" "gitee.com/timedb/wheatCache/pkg/logx" "gitee.com/timedb/wheatCache/pkg/proto" "gitee.com/timedb/wheatCache/pkg/structure/stringx" "github.com/stretchr/testify/require" - "testing" - "time" ) func TestWorker(t *testing.T) { @@ -53,6 +54,6 @@ func TestSingleCache_DelToClearSize(t *testing.T) { workEvent.StartWaitEvent(2 * time.Second) } - time.Sleep(5<<10 * time.Second) + time.Sleep(5 * time.Second) logx.Info("end size is %d", lru.nowSize) } diff --git a/pkg/util/skiplist/skiplist_test.go b/pkg/util/skiplist/skiplist_test.go index 7e28e7b..a200363 100644 --- a/pkg/util/skiplist/skiplist_test.go +++ b/pkg/util/skiplist/skiplist_test.go @@ -2,11 +2,12 @@ package skiplist import ( "fmt" - "gitee.com/timedb/wheatCache/pkg/logx" - "github.com/stretchr/testify/require" "math/rand" "testing" "time" + + "gitee.com/timedb/wheatCache/pkg/logx" + "github.com/stretchr/testify/require" ) // 时间测试 @@ -66,3 +67,39 @@ func Test_skipList_ClearLeft(t *testing.T) { require.Equal(t, s.Get(20), nil) } + +func TestSkipList_PopRangeByScore(t *testing.T) { + startNum := 5 + endNum := 79 + result := make([]interface{}, 0) + for i := startNum; i <= endNum; i++ { + result = append(result, i) + } + + for i := 0; i < 100; i++ { + s := NewSkipList(14) + for i := 0; i < 100; i++ { + s.Insert(float64(i), i) + } + res := s.PopRangeByScore(float64(startNum), float64(endNum)) + require.Equal(t, res, result) + } +} + +func TestSkipList_PopRight(t *testing.T) { + score := 33 + result := make([]interface{}, 0) + for i := score; i < 100; i++ { + result = append(result, i) + } + + for i := 0; i < 100; i++ { + s := NewSkipList(14) + for i := 0; i < 100; i++ { + s.Insert(float64(i), i) + } + res := s.PopRight(float64(score)) + require.Equal(t, res, result) + s.debugPrint() + } +}