github.com/TeaOSLab/EdgeNode@v1.3.8/internal/stats/traffic_stat_manager_test.go (about)

     1  package stats
     2  
     3  import (
     4  	"github.com/iwind/TeaGo/rands"
     5  	"github.com/iwind/TeaGo/types"
     6  	"math/rand"
     7  	"runtime"
     8  	"testing"
     9  )
    10  
    11  func TestTrafficStatManager_Add(t *testing.T) {
    12  	manager := NewTrafficStatManager()
    13  	for i := 0; i < 100; i++ {
    14  		manager.Add(1, 1, "goedge.cn", 1, 0, 0, 0, 0, 0, 0, false, 0)
    15  	}
    16  	t.Log(manager.itemMap)
    17  }
    18  
    19  func TestTrafficStatManager_Upload(t *testing.T) {
    20  	manager := NewTrafficStatManager()
    21  	for i := 0; i < 100; i++ {
    22  		manager.Add(1, 1, "goedge.cn"+types.String(rands.Int(0, 10)), 1, 0, 1, 0, 0, 0, 0, false, 0)
    23  	}
    24  	err := manager.Upload()
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	t.Log("ok")
    29  }
    30  
    31  func BenchmarkTrafficStatManager_Add(b *testing.B) {
    32  	runtime.GOMAXPROCS(1)
    33  
    34  	var manager = NewTrafficStatManager()
    35  	b.ResetTimer()
    36  
    37  	b.RunParallel(func(pb *testing.PB) {
    38  		for pb.Next() {
    39  			manager.Add(1, 1, "goedge.cn"+types.String(rand.Int63()%10), 1024, 1, 0, 0, 0, 0, 0, false, 0)
    40  		}
    41  	})
    42  }