From a25c170a1b7eab5d783b45c235cc5c4794875e9d Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 22 Apr 2024 18:46:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/list_file_kv_test.go | 50 +++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/internal/caches/list_file_kv_test.go b/internal/caches/list_file_kv_test.go index 0cfdbf5..d1bf457 100644 --- a/internal/caches/list_file_kv_test.go +++ b/internal/caches/list_file_kv_test.go @@ -91,7 +91,7 @@ func TestKVFileList_Add_Many(t *testing.T) { err := list.Add(stringutil.Md5(strconv.Itoa(i)), &caches.Item{ Type: caches.ItemTypeFile, Key: "https://www.example.com/index.html" + strconv.Itoa(i), - ExpiresAt: time.Now().Unix() + 60, + ExpiresAt: time.Now().Unix() + 3600, StaleAt: 0, HeaderSize: 0, BodySize: int64(rand.Int() % 1_000_000), @@ -176,6 +176,32 @@ func TestKVFileList_Exist(t *testing.T) { } } +func TestKVFileList_ExistMany(t *testing.T) { + var list = testOpenKVFileList(t) + defer func() { + _ = list.Close() + }() + + var countFound int + var count = 10 + if testutils.IsSingleTesting() { + count = 2_000_000 + } + + var before = time.Now() + for i := 0; i < count; i++ { + ok, _, err := list.Exist(stringutil.Md5(strconv.Itoa(i))) + if err != nil { + t.Fatal(err) + } + if ok { + countFound++ + } + } + var costSeconds = time.Since(before).Seconds() + t.Log("total:", costSeconds*1000, "ms", "found:", countFound, "qps:", fmt.Sprintf("%.2fK/s", float64(count)/costSeconds/1000), "per read:", fmt.Sprintf("%.4fms", costSeconds*1000/float64(count))) +} + func TestKVFileList_ExistQuick(t *testing.T) { var list = testOpenKVFileList(t) defer func() { @@ -211,6 +237,28 @@ func TestKVFileList_Remove(t *testing.T) { } } +func TestKVFileList_RemoveMany(t *testing.T) { + var list = testOpenKVFileList(t) + defer func() { + _ = list.Close() + }() + + var count = 10 + if testutils.IsSingleTesting() { + count = 2_000_000 + } + + var before = time.Now() + for i := 0; i < count; i++ { + err := list.Remove(stringutil.Md5(strconv.Itoa(i))) + if err != nil { + t.Fatal(err) + } + } + var costSeconds = time.Since(before).Seconds() + t.Log("total:", costSeconds*1000, "ms", "qps:", fmt.Sprintf("%.2fK/s", float64(count)/costSeconds/1000), "per delete:", fmt.Sprintf("%.4fms", costSeconds*1000/float64(count))) +} + func TestKVFileList_CleanAll(t *testing.T) { var list = testOpenKVFileList(t) defer func() {