github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/ratelimit/counter_test.go (about) 1 // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package ratelimit_test 4 5 import ( 6 "github.com/TeaOSLab/EdgeNode/internal/utils/ratelimit" 7 "github.com/TeaOSLab/EdgeNode/internal/utils/testutils" 8 "testing" 9 "time" 10 ) 11 12 func TestCounter_ACK(t *testing.T) { 13 if !testutils.IsSingleTesting() { 14 return 15 } 16 17 var counter = ratelimit.NewCounter(10) 18 19 go func() { 20 for i := 0; i < 10; i++ { 21 counter.Ack() 22 } 23 //counter.Release() 24 t.Log("waiting", time.Now().Unix()) 25 counter.Ack() 26 t.Log("done", time.Now().Unix()) 27 }() 28 29 time.Sleep(1 * time.Second) 30 counter.Close() 31 time.Sleep(1 * time.Second) 32 } 33 34 func TestCounter_Release(t *testing.T) { 35 var counter = ratelimit.NewCounter(10) 36 37 for i := 0; i < 10; i++ { 38 counter.Ack() 39 } 40 for i := 0; i < 10; i++ { 41 counter.Release() 42 } 43 t.Log(counter.Len()) 44 }