Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added some vows

  • Loading branch information...
commit b4159a286829ec447e7491a3dcdfbed7cf4a53f5 1 parent 8d52ab6
@DamonOehlman authored
View
3  lib/collector.js
@@ -81,15 +81,12 @@ Collector.prototype.scheduleAgents = function() {
if (typeof agent.frequency == 'string') {
// check the pattern is a valid cron pattern, and then register the job
new cron.CronTime(agent.frequency);
- console.log('pattern ok, registering agent');
agent.cron = new cron.CronJob(agent.frequency, function() {
collector.runAgent(agent);
});
}
else {
- console.log('agent specified interval, scheduling');
-
setInterval(function() {
collector.runAgent(agent);
}, agent.frequency);
View
19 lib/sampledb.js
@@ -10,7 +10,8 @@ SampleDB.prototype.close = function() {
}; // close
SampleDB.prototype.getSince = function(time, callback, maxItems) {
- var targetKey = time.toString(),
+ var error,
+ targetKey = time.toString(),
iterator = this.storage.newIterator({}),
itemCount = maxItems || 1000,
startTick,
@@ -54,13 +55,15 @@ SampleDB.prototype.getSince = function(time, callback, maxItems) {
} // while
// trigger the callback
- callback({
- start: startTick,
- end: lastTick,
- more: itemCount <= 0,
-
- items: items
- });
+ if (callback) {
+ callback(error, {
+ start: startTick,
+ end: lastTick,
+ more: itemCount <= 0,
+
+ items: items
+ });
+ } // if
}; // getSince
SampleDB.prototype.save = function(type, data, details) {
View
16 test/takesample.js
@@ -1,16 +0,0 @@
-var collector = require('../lib/collector'),
- collectionProcess,
- startTick = new Date().getTime();
-
-console.log('Collecting 5 seconds worth of data');
-
-collectionProcess = collector.collectToDB();
-setTimeout(function() {
- collectionProcess.db.getSince(startTick, function(results) {
- for (var key in results.items) {
- console.log(key, results.items[key].length);
- } // for
- });
-
- collectionProcess.stop();
-}, 5000);
View
34 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();
Please sign in to comment.
Something went wrong with that request. Please try again.