Skip to content

Commit

Permalink
Merge pull request #244 from trailsjs/243-move-performance-test
Browse files Browse the repository at this point in the history
Move the performance cases to another new performance test suite
  • Loading branch information
tjwebb authored Dec 21, 2016
2 parents 765e59d + c3bd856 commit c313b4c
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
"scripts": {
"test": "eslint . && mocha",
"test-performance": "eslint . && mocha test-performance",
"coverage": "istanbul cover _mocha",
"ci": "cd .. && ci"
},
Expand Down
3 changes: 3 additions & 0 deletions test-performance/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "trails/test"
}
131 changes: 131 additions & 0 deletions test-performance/lib/pathfinder.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
})

6 changes: 6 additions & 0 deletions test-performance/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--reporter spec
--recursive
--full-trace
--no-exit
--check-leaks
--globals app
20 changes: 20 additions & 0 deletions test-performance/testapp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const smokesignals = require('smokesignals')

module.exports = {
api: {

},
config: {
main: {
paths: {
root: __dirname
}
},
log: {
logger: new smokesignals.Logger('silent')
}
},
pkg: {

}
}
24 changes: 0 additions & 24 deletions test/lib/pathfinder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
Expand Down

0 comments on commit c313b4c

Please sign in to comment.