Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samogot committed Nov 13, 2018
1 parent 4b96309 commit c65262e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/throttle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var osmosis = require('../index'),
server = require('./server'),
url = server.host + ':' + server.port;


module.exports.on = function (assert) {
var date0 = +Date.now(), interval = 2000;
osmosis.get(url + '/get')
.throttle(2, interval)
.then(function () {
var date = +Date.now();
assert.ok(date - date0 < interval);
})
.get(url + '/get')
.then(function () {
var date = +Date.now();
assert.ok(date - date0 < interval);
})
.get(url + '/get')
.then(function () {
var date = +Date.now();
assert.ok(date - date0 >= interval);
})
.done(function () {
assert.done();
});
};

module.exports.off = function (assert) {
var date0 = +Date.now(), interval = 2000;
osmosis.get(url + '/get')
.then(function () {
var date = +Date.now();
assert.ok(date - date0 < interval);
})
.get(url + '/get')
.then(function () {
var date = +Date.now();
assert.ok(date - date0 < interval);
})
.get(url + '/get')
.then(function () {
var date = +Date.now();
assert.ok(date - date0 < interval);
})
.done(function () {
assert.done();
});
};

0 comments on commit c65262e

Please sign in to comment.