Skip to content

Commit

Permalink
Add test for issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyskn committed Jan 29, 2014
1 parent 54b38df commit edabce4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "Manage timeseries data storage in Redis with ease",
"main": "index.js",
"scripts": {
"test": "npm test"
"test": "./node_modules/.bin/vows test/*.js"
},
"engines": {
"node": ">=0.10.0"
"node": ">=0.10.0"
},
"repository": {
"type": "git",
"url": "git://github.com/tonyskn/node-redis-timeseries.git"
"type": "git",
"url": "git://github.com/tonyskn/node-redis-timeseries.git"
},
"keywords": [
"Redis",
Expand All @@ -24,6 +24,8 @@
},
"devDependencies": {
"redis": "0.x",
"hiredis": "0.x"
"hiredis": "0.x",
"async": "~0.2.10",
"vows": "~0.7.0"
}
}
46 changes: 46 additions & 0 deletions test/concurrentTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var async = require('async'),
vows = require('vows'),
assert = require('assert'),
redis = require('redis').createClient(),
TimeSeries = require('../');

// number of concurrent requests
var N = 15;

function range(n) {
return Array.apply(null, Array(n)).map(function (_, i) {return i;});
}

vows.describe('TimeSeries Tests').addBatch({
'When recording hits concurrently': {
topic: function() {
var ts = new TimeSeries(redis);

// Reduce granularities for easier testing
ts.granularities = {
'h' : { ttl: ts.days(7), duration: ts.hours(1) }
};

// Build N concurrent hit queries
function handler(i) {
return function(callback) {
ts.recordHit('key_'+i).exec(callback);
};
}

// Select non-default test db
redis.select(9);
redis.flushdb();

async.parallel(range(N).map(handler), this.callback);
},

"we get correct results": function(results) {
redis.flushdb();

var expected = range(N).map(function() { return [1,1]; });

assert.deepEqual(results, expected);
}
}
}).export(module);

0 comments on commit edabce4

Please sign in to comment.