From c3bd8569893a051dc1a8f2cae966b3a7eec73d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Catriel=20M=C3=BCller?= Date: Fri, 7 Oct 2016 10:42:16 -0300 Subject: [PATCH] Move the performance cases to another new performance test suite --- package.json | 1 + test-performance/.eslintrc.json | 3 + test-performance/lib/pathfinder.test.js | 131 ++++++++++++++++++++++++ test-performance/mocha.opts | 6 ++ test-performance/testapp.js | 20 ++++ test/lib/pathfinder.test.js | 24 ----- 6 files changed, 161 insertions(+), 24 deletions(-) create mode 100644 test-performance/.eslintrc.json create mode 100644 test-performance/lib/pathfinder.test.js create mode 100644 test-performance/mocha.opts create mode 100644 test-performance/testapp.js diff --git a/package.json b/package.json index 10e2ce4..20ee85f 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ ], "scripts": { "test": "eslint . && mocha", + "test-performance": "eslint . && mocha test-performance", "coverage": "istanbul cover _mocha", "ci": "cd .. && ci" }, diff --git a/test-performance/.eslintrc.json b/test-performance/.eslintrc.json new file mode 100644 index 0000000..be161bb --- /dev/null +++ b/test-performance/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "trails/test" +} diff --git a/test-performance/lib/pathfinder.test.js b/test-performance/lib/pathfinder.test.js new file mode 100644 index 0000000..5b53ade --- /dev/null +++ b/test-performance/lib/pathfinder.test.js @@ -0,0 +1,131 @@ +'use strict' + +const assert = require('assert') +const lib = require('../../lib') +const smokesignals = require('smokesignals') + +describe('lib.Pathfinder', () => { + describe('Lifecycle', () => { + const app = new smokesignals.TrailsApp() + const packs = [ + new smokesignals.Trailpack(app, { + trailpack: { + lifecycle: { + configure: { + listen: [ ], + emit: [ 'pack0:configured' ] + }, + initialize: { + listen: [ ], + emit: [ 'pack0:initialized' ] + } + } + } + }, 'pack0'), + + new smokesignals.Trailpack(app, { + trailpack: { + lifecycle: { + configure: { + listen: [ 'pack0:configured' ], + emit: [ 'pack1:configured' ] + }, + initialize: { + emit: [ 'pack1:initialized', 'pack1:custom' ] + } + } + } + }, 'pack1'), + + new smokesignals.Trailpack(app, { + trailpack: { + lifecycle: { + configure: { + listen: [ 'pack1:configured' ], + emit: [ 'pack2:configured' ] + }, + initialize: { + listen: [ 'pack1:initialized', 'pack1:custom' ], + emit: [ 'pack2:initialized' ] + } + } + } + }, 'pack2'), + + new smokesignals.Trailpack(app, { + trailpack: { + lifecycle: { + configure: { + listen: [ 'pack2:configured' ], + emit: [ 'pack3:configured' ] + }, + initialize: { + listen: [ 'pack2:initialized', 'pack1:custom' ], + emit: [ 'pack3:initialized' ] + } + } + } + }, 'pack3'), + + new smokesignals.Trailpack(app, { + trailpack: { + lifecycle: { + // dependency with no route to source + configure: { + listen: [ 'packX:configured' ], + emit: [ 'pack4:configured' ] + }, + // dependency on pack with circular dependency + initialize: { + listen: [ 'pack5:initialized', 'pack0:initialized' ] + } + } + } + }, 'pack4'), + + // circular dependency + new smokesignals.Trailpack(app, { + trailpack: { + lifecycle: { + configure: { + listen: [ 'pack5:configured' ], + emit: [ 'pack5:configured' ] + }, + initialize: { + listen: [ 'pack4:initialized' ], + emit: [ 'pack5:initialized' ] + } + } + } + }, 'pack5') + ] + + describe('#isComplete', () => { + it('should execute in under 5ms (n=6, with errors)', () => { + const t0 = process.hrtime() + const path = [ packs[0], packs[1], packs[2], packs[3], packs[4], packs[5] ] + + const complete = lib.Pathfinder.isComplete(path) + + const t1 = process.hrtime(t0) + const t = t1[1] / 1e6 + + assert(t < 5, `actual time: ${t} ms`) + assert(!complete) + }) + it('should execute in under 2ms (n=4, no errors)', () => { + const t0 = process.hrtime() + const path = [ packs[0], packs[1], packs[2], packs[3] ] + + const complete = lib.Pathfinder.isComplete(path) + + const t1 = process.hrtime(t0) + const t = t1[1] / 1e6 + + assert(t < 2, `actual time: ${t} ms`) + assert(complete) + }) + }) + }) +}) + diff --git a/test-performance/mocha.opts b/test-performance/mocha.opts new file mode 100644 index 0000000..09182a0 --- /dev/null +++ b/test-performance/mocha.opts @@ -0,0 +1,6 @@ +--reporter spec +--recursive +--full-trace +--no-exit +--check-leaks +--globals app diff --git a/test-performance/testapp.js b/test-performance/testapp.js new file mode 100644 index 0000000..513a03b --- /dev/null +++ b/test-performance/testapp.js @@ -0,0 +1,20 @@ +const smokesignals = require('smokesignals') + +module.exports = { + api: { + + }, + config: { + main: { + paths: { + root: __dirname + } + }, + log: { + logger: new smokesignals.Logger('silent') + } + }, + pkg: { + + } +} diff --git a/test/lib/pathfinder.test.js b/test/lib/pathfinder.test.js index 3d73ddf..aecd94f 100644 --- a/test/lib/pathfinder.test.js +++ b/test/lib/pathfinder.test.js @@ -356,30 +356,6 @@ describe('lib.Pathfinder', () => { const valid = lib.Pathfinder.isComplete(path) assert(!valid) }) - it('should execute in under 5ms (n=6, with errors)', () => { - const t0 = process.hrtime() - const path = [ packs[0], packs[1], packs[2], packs[3], packs[4], packs[5] ] - - const complete = lib.Pathfinder.isComplete(path) - - const t1 = process.hrtime(t0) - const t = t1[1] / 1e6 - - assert(t < 5, `actual time: ${t} ms`) - assert(!complete) - }) - it('should execute in under 2ms (n=4, no errors)', () => { - const t0 = process.hrtime() - const path = [ packs[0], packs[1], packs[2], packs[3] ] - - const complete = lib.Pathfinder.isComplete(path) - - const t1 = process.hrtime(t0) - const t = t1[1] / 1e6 - - assert(t < 2, `actual time: ${t} ms`) - assert(complete) - }) }) }) })