Skip to content

Commit

Permalink
pmx@1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Jan 16, 2017
1 parent aabb4cd commit 3893628
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "pmx",
"version": "1.0.0",
"version": "1.0.1",
"description": "PM2/Keymetrics advanced API",
"main": "index.js",
"dependencies": {
"debug": "^2.6",
"json-stringify-safe": "^5.0",
"vxx": "^1.0.0"
"vxx": "^1.0.3"
},
"devDependencies": {
"express": "*",
Expand Down
8 changes: 2 additions & 6 deletions test/fixtures/vxx-e2e/app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

var pmx = require('../../..');

pmx.init({
transactions : true
});

global._db = {};

var mongoose = require('mongoose');
Expand Down Expand Up @@ -71,7 +67,7 @@ function connectToMongoDB(cb) {
app.get('/db1/save', function(req, res) {
var user = new _db.User({
username : 'yolo',
phone : '06'
phone : '06'
});

user.save(function() {
Expand Down Expand Up @@ -150,7 +146,7 @@ pmx.action('launchQueryToDbRoutes', function(reply) {
});

pmx.action('db1get', function(reply) {
for (var i = 0; i < 10; i++) {
for (var i = 0; i < 1; i++) {
doQuery('/db1/get');
}
reply('launched');
Expand Down
101 changes: 57 additions & 44 deletions test/vxx.e2e.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ describe('Programmatically test interactor', function() {
});

describe('application testing', function() {
afterEach(function() {
//console.log(sub);
//sub.unsubscribe();
});

it('should start test application', function(done) {
sub.once('message', function(data) {
var packet = JSON.parse(data);
Expand All @@ -62,13 +57,16 @@ describe('Programmatically test interactor', function() {

pm2.start({
script : 'app.js',
name : 'API'
name : 'API',
trace : true
}, function(err, data) {

if (err) done(err);
});
});

it('should get transaction trace via interactor output', function(done) {
pm2.trigger('API', 'launchMock');

(function callAgain() {
sub.once('message', function(data) {
var packet = JSON.parse(data);
Expand All @@ -81,65 +79,74 @@ describe('Programmatically test interactor', function() {
// Should only find 3 different routes
Object.keys(packet.data['axm:transaction'][0].data.routes).length.should.eql(3);

var route = packet.data['axm:transaction'][0].data.routes['/'][0];
var route;

packet.data['axm:transaction'][0].data.routes.forEach(function(_route) {
if (_route.path == '/')
route = _route;
});

// Right property keys
route.should.have.properties(['min', 'max', 'mean', 'meter', 'count', 'spans']);
route.meta.should.have.properties(['mean', 'max', 'min', 'count']);
route.variances.length.should.eql(1);
done();
}
else callAgain();
});
})()

pm2.trigger('API', 'launchMock');
});

it('should get database transaction trace (save)', function(done) {
(function callAgain() {
sub.once('message', function(data) {
var packet = JSON.parse(data);

if (packet.data['axm:transaction']) {
// Should now route summary contains 4 routes
Object.keys(packet.data['axm:transaction'][0].data.routes).length.should.eql(4);
// @question: Why extra .spans at the end?
var tracing = packet.data['axm:transaction'][0].data.routes['/db1/save'][0].spans;
// Should count 10 transactions
packet.data['axm:transaction'][0].data.routes['/db1/save'][0].count.should.eql(10);
//console.log(packet.data['axm:transaction'][0].data.routes['/db1/save']);
tracing.length.should.eql(2);
tracing[1].name.should.eql('mongo-insert');
done();
}
else
callAgain();
});
})()

pm2.trigger('API', 'launchQueryToDbRoutes');
});

it('should get simple database transaction trace (find)', function(done) {
(function callAgain() {
sub.once('message', function(data) {
var packet = JSON.parse(data);

if (packet.data['axm:transaction']) {
console.log(packet.data['axm:transaction']);
// Should now route summary contains 5 routes
Object.keys(packet.data['axm:transaction'][0].data.routes).length.should.eql(5);

// @bug: should contain only 1 transaction not 2 (only find)
packet.data['axm:transaction'][0].data.routes['/db1/get'][0].spans.length.should.eql(3);

packet.data['axm:transaction'][0].data.routes.length.should.eql(4);

packet.data['axm:transaction'][0].data.routes.forEach(function(_route) {
if (_route.path == '/db1/save') {
_route.variances.length.should.eql(1);
_route.meta.should.have.properties(['mean', 'max', 'min', 'count']);
_route.variances[0].spans[1].name.should.eql('mongo-insert');
}
});
done();
}
else
callAgain();
});
})()
});

it('should get simple database transaction trace (find)', function(done) {
pm2.trigger('API', 'db1get');

setTimeout(function() {
(function callAgain() {
sub.once('message', function(data) {
var packet = JSON.parse(data);

if (packet.data['axm:transaction']) {
// Should now route summary contains 5 routes
Object.keys(packet.data['axm:transaction'][0].data.routes).length.should.eql(5);

// @bug: should contain only 1 transaction not 2 (only find)
packet.data['axm:transaction'][0].data.routes.forEach(function(_route) {
if (_route.path == '/db1/get') {
_route.variances.forEach(function(vari) {
vari.spans.length.should.eql(2);
});
}
});
done();
}
else
callAgain();
});
})()
}, 1000);
});

it('should get multi database transaction trace (find + findOne)', function(done) {
Expand All @@ -151,8 +158,14 @@ describe('Programmatically test interactor', function() {
// Should now route summary contains 5 routes
Object.keys(packet.data['axm:transaction'][0].data.routes).length.should.eql(6);

// @bug: should contain only 2 transactions not 3 (find + findOne)
packet.data['axm:transaction'][0].data.routes['/db1/multi'][0].spans.length.should.eql(4);
// @bug: should contain only 1 transaction not 2 (only find)
packet.data['axm:transaction'][0].data.routes.forEach(function(_route) {
if (_route.path == '/db1/multi') {
_route.variances.forEach(function(vari) {
vari.spans.length.should.eql(3);
});
}
});

done();
}
Expand Down

0 comments on commit 3893628

Please sign in to comment.