From 81fdc337c9a422206ae15bf843a22e09784dfb8f Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 24 Dec 2023 16:08:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A1=E6=95=B0=E5=99=A8?= =?UTF-8?q?=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/utils/counters/counter_test.go | 2 +- internal/utils/counters/item_test.go | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/utils/counters/counter_test.go b/internal/utils/counters/counter_test.go index 912a7a0..2c5376c 100644 --- a/internal/utils/counters/counter_test.go +++ b/internal/utils/counters/counter_test.go @@ -91,7 +91,7 @@ func TestCounterMemory(t *testing.T) { var stat1 = &runtime.MemStats{} runtime.ReadMemStats(stat1) - t.Log((stat1.TotalAlloc-stat.TotalAlloc)/(1<<20), "MB") + t.Log((stat1.HeapInuse-stat.HeapInuse)/(1<<20), "MB") t.Log(counter.TotalItems()) diff --git a/internal/utils/counters/item_test.go b/internal/utils/counters/item_test.go index 098ed1f..7e12a64 100644 --- a/internal/utils/counters/item_test.go +++ b/internal/utils/counters/item_test.go @@ -6,6 +6,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/utils/counters" "github.com/TeaOSLab/EdgeNode/internal/utils/testutils" "github.com/iwind/TeaGo/assert" + "github.com/iwind/TeaGo/types" timeutil "github.com/iwind/TeaGo/utils/time" "runtime" "testing" @@ -41,9 +42,9 @@ func TestItem_Increase2(t *testing.T) { var a = assert.NewAssertion(t) - var item = counters.NewItem[uint32](20) + var item = counters.NewItem[uint32](23) for i := 0; i < 100; i++ { - t.Log(item.Increase(), item.Sum(), timeutil.Format("H:i:s")) + t.Log("round "+types.String(i)+":", item.Increase(), item.Sum(), timeutil.Format("H:i:s")) time.Sleep(2 * time.Second) } @@ -56,14 +57,14 @@ func TestItem_IsExpired(t *testing.T) { return } - var currentTime = time.Now().Unix() - var item = counters.NewItem[uint32](10) - t.Log(item.IsExpired(currentTime)) + t.Log(item.IsExpired(time.Now().Unix())) time.Sleep(10 * time.Second) - t.Log(item.IsExpired(currentTime)) + t.Log(item.IsExpired(time.Now().Unix())) time.Sleep(2 * time.Second) - t.Log(item.IsExpired(currentTime)) + t.Log(item.IsExpired(time.Now().Unix())) + time.Sleep(2 * time.Second) + t.Log(item.IsExpired(time.Now().Unix())) } func BenchmarkItem_Increase(b *testing.B) {