Blame view

test/stat.js 1.12 KB
adfda8e1   Arsisakarn Srilatanart   initial commit fr...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require('./setup');
var stat = require('../model/stat');
var _ = require('lodash');
var Promise = require('bluebird');
var fs = require('fs');

describe('Stat Model', function() {

  var validData = [
    {key: 'a', threshold: 2, threshold_inv: 1},
    {key: 'b', threshold: 2},
    {key: 'c', threshold_inv: 1},
    {key: 'd', threshold: 2}
  ]

  var stat_object = new stat('./log_test/', {rotation:5000, maxsize:5000, interval:1, data:validData})

  before(function(done) {
    validData = ['a', 'b'];
    done();
  });

  it('should stat correctly (whole process)', function(done) {
    stat_object.start();
    return Promise.delay(100)
      .then(function() {
        Promise.all(_.map(_.times(100, String), function(){
          stat_object.increment(validData[0]);
        }))
      })
      .then(function() {
        return Promise.delay(100)
      })
      .then(function() {
        stat_object.increment(validData[0]);
        stat_object.increment(validData[1]);
      })
      .then(function() {
        return Promise.delay(100)
      })
      .then(function() {
        stat_object.stop();
        done();
      })

  });


});