github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/ratelimit/bandwidth_test.go (about)

     1  // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package ratelimit_test
     4  
     5  import (
     6  	"context"
     7  	"github.com/TeaOSLab/EdgeNode/internal/utils/ratelimit"
     8  	"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
     9  	"testing"
    10  )
    11  
    12  func TestBandwidth(t *testing.T) {
    13  	if !testutils.IsSingleTesting() {
    14  		return
    15  	}
    16  
    17  	var bandwidth = ratelimit.NewBandwidth(32 << 10)
    18  	bandwidth.Ack(context.Background(), 123)
    19  	bandwidth.Ack(context.Background(), 16 << 10)
    20  	bandwidth.Ack(context.Background(), 32 << 10)
    21  }
    22  
    23  func TestBandwidth_0(t *testing.T) {
    24  	var bandwidth = ratelimit.NewBandwidth(0)
    25  	bandwidth.Ack(context.Background(), 123)
    26  	bandwidth.Ack(context.Background(), 123456)
    27  }