mirror of
https://github.com/buger/goreplay.git
synced 2024-04-21 12:32:02 +00:00
Some formatting fixes
This commit is contained in:
+4
-4
@@ -3,10 +3,10 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
type Limiter struct {
|
||||
@@ -40,21 +40,21 @@ func NewLimiter(plugin interface{}, options string) io.ReadWriter {
|
||||
}
|
||||
|
||||
func (l *Limiter) isLimited() bool {
|
||||
if (l.isPercent) {
|
||||
if l.isPercent {
|
||||
return l.limit <= rand.Intn(100)
|
||||
}
|
||||
|
||||
if (time.Now().UnixNano() - l.currentTime) > time.Second.Nanoseconds() {
|
||||
l.currentTime = time.Now().UnixNano()
|
||||
l.currentRPS = 0
|
||||
}
|
||||
}
|
||||
|
||||
if l.currentRPS >= l.limit {
|
||||
return true
|
||||
}
|
||||
|
||||
l.currentRPS++
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -54,7 +54,6 @@ func TestInputLimiter(t *testing.T) {
|
||||
close(quit)
|
||||
}
|
||||
|
||||
|
||||
// Should limit all requests
|
||||
func TestPercentLimiter1(t *testing.T) {
|
||||
wg := new(sync.WaitGroup)
|
||||
@@ -102,4 +101,4 @@ func TestPercentLimiter2(t *testing.T) {
|
||||
wg.Wait()
|
||||
|
||||
close(quit)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user