test(skiplist, ttl): update ttl

This commit is contained in:
bandl 2021-10-18 23:58:46 +08:00
parent ac8f748356
commit 95d3fdbd17
3 changed files with 46 additions and 7 deletions

View File

@ -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) {

View File

@ -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)
}

View File

@ -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()
}
}