parent
71649abefe
commit
5d6392b65d
1 changed files with 6 additions and 2 deletions
|
@ -9,15 +9,15 @@ import (
|
|||
"net/http/httptest"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestThrottle(t *testing.T) {
|
||||
const threshold = 1
|
||||
busy := make(chan struct{})
|
||||
|
||||
srv := httptest.NewServer(throttledFn(threshold,
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
<-busy
|
||||
}),
|
||||
)
|
||||
|
||||
|
@ -35,6 +35,10 @@ func TestThrottle(t *testing.T) {
|
|||
got := make(map[int]int, cap(codes))
|
||||
for i := 0; i < cap(codes); i++ {
|
||||
got[<-codes]++
|
||||
|
||||
if i == 0 {
|
||||
close(busy)
|
||||
}
|
||||
}
|
||||
|
||||
want := map[int]int{200: 1, 429: 1}
|
||||
|
|
Loading…
Reference in a new issue