2024-07-27 15:42:50 +08:00
|
|
|
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
|
2024-01-11 15:25:47 +08:00
|
|
|
|
|
|
|
|
package ratelimit_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-07-27 15:42:50 +08:00
|
|
|
"testing"
|
|
|
|
|
|
2024-01-11 15:25:47 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/utils/ratelimit"
|
|
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestBandwidth(t *testing.T) {
|
|
|
|
|
if !testutils.IsSingleTesting() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bandwidth = ratelimit.NewBandwidth(32 << 10)
|
|
|
|
|
bandwidth.Ack(context.Background(), 123)
|
2024-07-27 15:42:50 +08:00
|
|
|
bandwidth.Ack(context.Background(), 16<<10)
|
|
|
|
|
bandwidth.Ack(context.Background(), 32<<10)
|
2024-01-11 15:25:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBandwidth_0(t *testing.T) {
|
|
|
|
|
var bandwidth = ratelimit.NewBandwidth(0)
|
|
|
|
|
bandwidth.Ack(context.Background(), 123)
|
|
|
|
|
bandwidth.Ack(context.Background(), 123456)
|
|
|
|
|
}
|