Skip to content
Snippets Groups Projects
Commit 33b75f13 authored by AlexStocks's avatar AlexStocks
Browse files

Fix: use 1e6 as ms

parent f4f346c1
No related branches found
No related tags found
No related merge requests found
......@@ -156,7 +156,9 @@ func WithToken(token string) option {
if len(token) > 0 {
value := token
if strings.ToLower(token) == "true" || strings.ToLower(token) == "default" {
value = uuid.NewV4().String()
if id, err := uuid.NewV4(); err == nil {
value = id.String()
}
}
url.SetParam(constant.TOKEN_KEY, value)
}
......
......@@ -79,7 +79,7 @@ func (impl *FixedWindowTpsLimitStrategyImpl) IsAllowable() bool {
func NewFixedWindowTpsLimitStrategyImpl(rate int, interval int) tps.TpsLimitStrategy {
return &FixedWindowTpsLimitStrategyImpl{
rate: int32(rate),
interval: int64(interval * 1000), // convert to ns
interval: int64(interval) * int64(time.Millisecond), // convert to ns
count: 0,
timestamp: time.Now().UnixNano(),
}
......
......@@ -36,7 +36,7 @@ func TestFixedWindowTpsLimitStrategyImpl_IsAllowable(t *testing.T) {
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
time.Sleep(time.Duration(2100 * 1000))
time.Sleep(2100 * time.Millisecond)
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
......
......@@ -83,7 +83,7 @@ func (impl *SlidingWindowTpsLimitStrategyImpl) IsAllowable() bool {
func NewSlidingWindowTpsLimitStrategyImpl(rate int, interval int) tps.TpsLimitStrategy {
return &SlidingWindowTpsLimitStrategyImpl{
rate: rate,
interval: int64(interval * 1000),
interval: int64(interval) * int64(time.Millisecond),
mutex: &sync.Mutex{},
queue: list.New(),
}
......
......@@ -31,14 +31,14 @@ func TestSlidingWindowTpsLimitStrategyImpl_IsAllowable(t *testing.T) {
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
time.Sleep(time.Duration(2100 * 1000))
time.Sleep(2100 * time.Millisecond)
assert.False(t, strategy.IsAllowable())
strategy = NewSlidingWindowTpsLimitStrategyImpl(2, 2000)
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
time.Sleep(time.Duration(2100 * 1000))
time.Sleep(2100 * time.Millisecond)
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
......
......@@ -36,7 +36,7 @@ func TestThreadSafeFixedWindowTpsLimitStrategyImpl_IsAllowable(t *testing.T) {
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
time.Sleep(time.Duration(2100 * 1000))
time.Sleep(2100 * time.Millisecond)
assert.True(t, strategy.IsAllowable())
assert.True(t, strategy.IsAllowable())
assert.False(t, strategy.IsAllowable())
......
......@@ -20,11 +20,17 @@
// Package filter is a generated GoMock package.
package impl
import (
reflect "reflect"
)
import (
gomock "github.com/golang/mock/gomock"
)
import (
common "github.com/apache/dubbo-go/common"
protocol "github.com/apache/dubbo-go/protocol"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
)
// MockTpsLimiter is a mock of TpsLimiter interface
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment