Skip to content

Commit

Permalink
Update deps to fix #1 and add test for it.
Browse files Browse the repository at this point in the history
  • Loading branch information
brycebaril committed Feb 9, 2014
1 parent a008242 commit 440a61a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
examples
test
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"test": "test"
},
"dependencies": {
"tokenthrottle": "~1.0.1",
"tokenthrottle": "~1.1.0",
"redis": "~0.10.0"
},
"devDependencies": {
"tape": "~2.3.2"
"tape": "~2.4.2"
},
"scripts": {
"test": "node test/"
Expand Down
32 changes: 32 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,36 @@ test("Override", function (t) {
})
})
}, 50)
})

test("Override rate only", function (t) {
t.plan(9)
var redisClient = redis.createClient()

var throttle = redisThrottle({
rate: 3,
burst: 3,
overrides: {
test: {rate: 0}
}
}, redisClient)
var i = 0
while (i++ < 3) {
// This is so much cleaner with setImmediate... *sigh 0.8.x*
setTimeout(function () {
throttle.rateLimit("test", function (err, limited) {
t.notOk(err)
t.notOk(limited, "Not throttled yet")
})
}, i * 10)
}
setTimeout(function () {
throttle.rateLimit("test", function (err, limited) {
t.notOk(err)
t.notOk(limited, "This one never gets throttled.")
redisClient.quit(function () {
t.ok(1, "redis client exited")
})
})
}, 50)
})

0 comments on commit 440a61a

Please sign in to comment.