Skip to content

Commit

Permalink
histogram/tags tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanchi-zendesk committed Jul 16, 2013
1 parent a335a19 commit 8d239d3
Showing 1 changed file with 76 additions and 15 deletions.
91 changes: 76 additions & 15 deletions test/test_statsd.js
Expand Up @@ -173,18 +173,18 @@ describe('StatsD', function(){
});
});

it('should send proper time format with prefix, suffix, sampling and callback', function(finished){
it('should send proper time format with prefix, suffix, sampling, tags and callback', function(finished){
var called = false;
udpTest(function(message, server){
assert.equal(message, 'foo.test.bar:42|ms|@0.5');
assert.equal(message, 'foo.test.bar:42|ms|@0.5|#host:xyz,datacenter:1');
assert.equal(called, true);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'foo.', '.bar');

statsd.timing('test', 42).sampleRate(0.5).send(function(){
statsd.timing('test', 42).sampleRate(0.5).tags(['host:xyz','datacenter:1']).send(function(){
called = true;
});
});
Expand Down Expand Up @@ -235,18 +235,18 @@ describe('StatsD', function(){
});
});

it('should send proper gauge format with prefix, suffix, sampling and callback', function(finished){
it('should send proper gauge format with prefix, suffix, sampling, tags and callback', function(finished){
var called = false;
udpTest(function(message, server){
assert.equal(message, 'foo.test.bar:42|g|@0.5');
assert.equal(message, 'foo.test.bar:42|g|@0.5|#host:xyz,datacenter:1');
assert.equal(called, true);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'foo.', '.bar');

statsd.gauge('test', 42).sampleRate(0.5).send(function(){
statsd.gauge('test', 42).sampleRate(0.5).tags(['host:xyz', 'datacenter:1']).send(function(){
called = true;
});
});
Expand Down Expand Up @@ -297,18 +297,18 @@ describe('StatsD', function(){
});
});

it('should send proper count format with prefix, suffix, sampling and callback', function(finished){
it('should send proper count format with prefix, suffix, sampling, tags and callback', function(finished){
var called = false;
udpTest(function(message, server){
assert.equal(message, 'foo.test.bar:42|c|@0.5');
assert.equal(message, 'foo.test.bar:42|c|@0.5|#host:xyz,datacenter:1');
assert.equal(called, true);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'foo.', '.bar');

statsd.increment('test', 42).sampleRate(0.5).send(function(){
statsd.increment('test', 42).sampleRate(0.5).tags(['host:xyz','datacenter:1']).send(function(){
called = true;
});
});
Expand Down Expand Up @@ -359,18 +359,18 @@ describe('StatsD', function(){
});
});

it('should send proper count format with prefix, suffix, sampling and callback', function(finished){
it('should send proper count format with prefix, suffix, sampling, tags and callback', function(finished){
var called = false;
udpTest(function(message, server){
assert.equal(message, 'foo.test.bar:-42|c|@0.5');
assert.equal(message, 'foo.test.bar:-42|c|@0.5|#host:xyz,datacenter:1');
assert.equal(called, true);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'foo.', '.bar');

statsd.decrement('test', 42).sampleRate(0.5).send(function(){
statsd.decrement('test', 42).sampleRate(0.5).tags(['host:xyz','datacenter:1']).send(function(){
called = true;
});
});
Expand Down Expand Up @@ -422,18 +422,18 @@ describe('StatsD', function(){
});
});

it('should send proper set format with prefix, suffix, sampling and callback', function(finished){
it('should send proper set format with prefix, suffix, sampling, tags and callback', function(finished){
var called = false;
udpTest(function(message, server){
assert.equal(message, 'foo.test.bar:42|s|@0.5');
assert.equal(message, 'foo.test.bar:42|s|@0.5|#host:xyz,datacenter:1');
assert.equal(called, true);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'foo.', '.bar');

statsd.unique('test', 42).sampleRate(0.5).send(function(){
statsd.unique('test', 42).sampleRate(0.5).tags(['host:xyz','datacenter:1']).send(function(){
called = true;
});
});
Expand Down Expand Up @@ -470,4 +470,65 @@ describe('StatsD', function(){
});
});

describe('#histogram', function(finished){
it('should send proper histogram format without prefix, suffix, sampling, tags and callback', function(finished){
udpTest(function(message, server){
assert.equal(message, 'test:42|h');
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port);

statsd.histogram('test', 42).send();
});
});

it('should send proper histogram format with prefix, suffix, sampling, tags and callback', function(finished){
var called = false;
udpTest(function(message, server){
assert.equal(message, 'foo.test.bar:42|h|@0.5|#host:xyz,datacenter:1');
assert.equal(called, true);
server.close();
finished();
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port, 'foo.', '.bar');

statsd.histogram('test', 42).sampleRate(0.5).tags(['host:xyz','datacenter:1']).send(function(){
called = true;
});
});
});

it('should properly send a and b with the same value', function(finished){
var called = 0,
messageNumber = 0;

udpTest(function(message, server){
if(messageNumber === 0){
assert.equal(message, 'a:42|h');
messageNumber += 1;
} else {
assert.equal(message, 'b:42|h');
server.close();
finished();
}
}, function(server){
var address = server.address(),
statsd = new StatsD(address.address, address.port);

statsd.histogram(['a', 'b'], 42).send(function(error, bytes){
called += 1;
assert.ok(called === 1); //ensure it only gets called once
assert.equal(error, null);
assert.equal(bytes, 12);
});
});
});

it('should send no histogram stat when a mock Client is used', function(finished){
assertMockClientMethod('histogram', finished);
});
});
});

0 comments on commit 8d239d3

Please sign in to comment.