Skip to content

Commit

Permalink
Added some vows
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonOehlman committed Aug 31, 2011
1 parent 8d52ab6 commit b4159a2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
3 changes: 0 additions & 3 deletions lib/collector.js
Expand Up @@ -81,15 +81,12 @@ Collector.prototype.scheduleAgents = function() {
if (typeof agent.frequency == 'string') { if (typeof agent.frequency == 'string') {
// check the pattern is a valid cron pattern, and then register the job // check the pattern is a valid cron pattern, and then register the job
new cron.CronTime(agent.frequency); new cron.CronTime(agent.frequency);
console.log('pattern ok, registering agent');


agent.cron = new cron.CronJob(agent.frequency, function() { agent.cron = new cron.CronJob(agent.frequency, function() {
collector.runAgent(agent); collector.runAgent(agent);
}); });
} }
else { else {
console.log('agent specified interval, scheduling');

setInterval(function() { setInterval(function() {
collector.runAgent(agent); collector.runAgent(agent);
}, agent.frequency); }, agent.frequency);
Expand Down
19 changes: 11 additions & 8 deletions lib/sampledb.js
Expand Up @@ -10,7 +10,8 @@ SampleDB.prototype.close = function() {
}; // close }; // close


SampleDB.prototype.getSince = function(time, callback, maxItems) { SampleDB.prototype.getSince = function(time, callback, maxItems) {
var targetKey = time.toString(), var error,
targetKey = time.toString(),
iterator = this.storage.newIterator({}), iterator = this.storage.newIterator({}),
itemCount = maxItems || 1000, itemCount = maxItems || 1000,
startTick, startTick,
Expand Down Expand Up @@ -54,13 +55,15 @@ SampleDB.prototype.getSince = function(time, callback, maxItems) {
} // while } // while


// trigger the callback // trigger the callback
callback({ if (callback) {
start: startTick, callback(error, {
end: lastTick, start: startTick,
more: itemCount <= 0, end: lastTick,

more: itemCount <= 0,
items: items
}); items: items
});
} // if
}; // getSince }; // getSince


SampleDB.prototype.save = function(type, data, details) { SampleDB.prototype.save = function(type, data, details) {
Expand Down
16 changes: 0 additions & 16 deletions test/takesample.js

This file was deleted.

34 changes: 34 additions & 0 deletions tests/db.js
@@ -0,0 +1,34 @@
var vows = require('vows'),
assert = require('assert'),
collector = require('../lib/collector'),
startTick = new Date().getTime();

vows.describe('Collection to DB').addBatch({
'When collecting samples': {
topic: function() {
var collectionProcess = collector.collectToDB(),
callback = this.callback;

setTimeout(function() {
collectionProcess.db.getSince(startTick, callback);
collectionProcess.stop();
}, 2000);
},

'we have results': function(err, results) {
assert.ok(results);
},

'samples have been collected': function(err, results) {
assert.ok(results.items.cpu && results.items.cpu.length > 0);
},

'start tick in results is sensible': function(err, results) {
assert.ok(Math.abs(results.start - startTick) < 500);
},

'end tick in results is sensible': function(err, results) {
assert.ok(Math.abs(results.end - (startTick + 2000)) < 500);
}
}
}).run();

0 comments on commit b4159a2

Please sign in to comment.