Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lonelycode committed Oct 7, 2015
1 parent d3456e1 commit 9aff352
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ func TestVersioningRequestFail(t *testing.T) {
thisSession.AccessRights = map[string]AccessDefinition{"9991": AccessDefinition{APIName: "Tyk Test API", APIID: "9991", Versions: []string{"v2"}}}

// no version allowed
spec.SessionManager.UpdateSession("1234", thisSession, 60)
spec.SessionManager.UpdateSession("zz1234", thisSession, 60)
uri := "/about-lonelycoder/"
method := "GET"

recorder := httptest.NewRecorder()
param := make(url.Values)
req, err := http.NewRequest(method, uri+param.Encode(), nil)
req.Header.Add("authorization", "1234")
req.Header.Add("authorization", "zz1234")
req.Header.Add("version", "v1")

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (l SessionLimiter) doRollingWindowWrite(key, rateLimiterKey, rateLimiterSen

log.Debug("Num Requests: ", ratePerPeriodNow)

// Subtract by 1 because of the delayed add in the window
if ratePerPeriodNow > (int(currentSession.Rate) - 1) {
// Subtract by 1 because of the delayed add in the window, and another subtraction because of the preemptive limit
if ratePerPeriodNow > (int(currentSession.Rate) - 2) {
// Set a sentinel value with expire
store.SetRawKey(rateLimiterSentinelKey, "1", int64(currentSession.Per))
}
Expand Down

0 comments on commit 9aff352

Please sign in to comment.