addRateLimitHeaders(w, statuses) compareStatusesToHeader(t, w.Header(), statuses) } func TestAddHeadersMultipleStatus(t *testing.T) { w := httptest.NewRecorder() statuses := []ratelimiter.Status{ {Capacity: uint(10), Reset: time.Now(), Remaining: uint(10), Name: "test1"}, {Capacity: uint(100), Reset: time.Now(), Remaining: uint(100), Name: "test2"}, {Capacity: uint(1000), Reset: time.Now(), Remaining: uint(1000), Name: "test3"}, } addRateLimitHeaders(w, statuses) compareStatusesToHeader(t, w.Header(), statuses) } var anyRequest = mock.AnythingOfTypeArgument("common.Request") var sphinxStatus = ratelimiter.Status{ Capacity: uint(10), Reset: time.Now(), Remaining: uint(10), Name: "test", } func TestHandleWhenNotFull(t *testing.T) { limiter := constructHTTPRateLimiter() w := httptest.NewRecorder() r, err := http.NewRequest("GET", "http://google.com", strings.NewReader("thebody")) if err != nil { t.Fatal(err) } statuses := []ratelimiter.Status{sphinxStatus}
func (s *ForwarderTestSuite) TestInvalidInflightDecrement() { var wg sync.WaitGroup wg.Add(1) listener := &EventListener{} listener.On("HandleEvent", mock.AnythingOfTypeArgument("forward.InflightRequestsMiscountEvent")).Run(func(args mock.Arguments) { wg.Done() }).Return() s.forwarder.inflight = 0 s.forwarder.RegisterListener(listener) s.forwarder.decrementInflight() s.Assertions.Equal(int64(0), s.forwarder.inflight, "Expected inflight to stay at 0 when decremented at 0") // wait for HandleEvent with forward.InflightRequestsMiscountEvent being called wg.Wait() }