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