Skip to content

Commit c313b4c

Browse files
authored
Merge pull request #244 from trailsjs/243-move-performance-test
Move the performance cases to another new performance test suite
2 parents 765e59d + c3bd856 commit c313b4c

File tree

6 files changed

+161
-24
lines changed

6 files changed

+161
-24
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
],
2222
"scripts": {
2323
"test": "eslint . && mocha",
24+
"test-performance": "eslint . && mocha test-performance",
2425
"coverage": "istanbul cover _mocha",
2526
"ci": "cd .. && ci"
2627
},

test-performance/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "trails/test"
3+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
'use strict'
2+
3+
const assert = require('assert')
4+
const lib = require('../../lib')
5+
const smokesignals = require('smokesignals')
6+
7+
describe('lib.Pathfinder', () => {
8+
describe('Lifecycle', () => {
9+
const app = new smokesignals.TrailsApp()
10+
const packs = [
11+
new smokesignals.Trailpack(app, {
12+
trailpack: {
13+
lifecycle: {
14+
configure: {
15+
listen: [ ],
16+
emit: [ 'pack0:configured' ]
17+
},
18+
initialize: {
19+
listen: [ ],
20+
emit: [ 'pack0:initialized' ]
21+
}
22+
}
23+
}
24+
}, 'pack0'),
25+
26+
new smokesignals.Trailpack(app, {
27+
trailpack: {
28+
lifecycle: {
29+
configure: {
30+
listen: [ 'pack0:configured' ],
31+
emit: [ 'pack1:configured' ]
32+
},
33+
initialize: {
34+
emit: [ 'pack1:initialized', 'pack1:custom' ]
35+
}
36+
}
37+
}
38+
}, 'pack1'),
39+
40+
new smokesignals.Trailpack(app, {
41+
trailpack: {
42+
lifecycle: {
43+
configure: {
44+
listen: [ 'pack1:configured' ],
45+
emit: [ 'pack2:configured' ]
46+
},
47+
initialize: {
48+
listen: [ 'pack1:initialized', 'pack1:custom' ],
49+
emit: [ 'pack2:initialized' ]
50+
}
51+
}
52+
}
53+
}, 'pack2'),
54+
55+
new smokesignals.Trailpack(app, {
56+
trailpack: {
57+
lifecycle: {
58+
configure: {
59+
listen: [ 'pack2:configured' ],
60+
emit: [ 'pack3:configured' ]
61+
},
62+
initialize: {
63+
listen: [ 'pack2:initialized', 'pack1:custom' ],
64+
emit: [ 'pack3:initialized' ]
65+
}
66+
}
67+
}
68+
}, 'pack3'),
69+
70+
new smokesignals.Trailpack(app, {
71+
trailpack: {
72+
lifecycle: {
73+
// dependency with no route to source
74+
configure: {
75+
listen: [ 'packX:configured' ],
76+
emit: [ 'pack4:configured' ]
77+
},
78+
// dependency on pack with circular dependency
79+
initialize: {
80+
listen: [ 'pack5:initialized', 'pack0:initialized' ]
81+
}
82+
}
83+
}
84+
}, 'pack4'),
85+
86+
// circular dependency
87+
new smokesignals.Trailpack(app, {
88+
trailpack: {
89+
lifecycle: {
90+
configure: {
91+
listen: [ 'pack5:configured' ],
92+
emit: [ 'pack5:configured' ]
93+
},
94+
initialize: {
95+
listen: [ 'pack4:initialized' ],
96+
emit: [ 'pack5:initialized' ]
97+
}
98+
}
99+
}
100+
}, 'pack5')
101+
]
102+
103+
describe('#isComplete', () => {
104+
it('should execute in under 5ms (n=6, with errors)', () => {
105+
const t0 = process.hrtime()
106+
const path = [ packs[0], packs[1], packs[2], packs[3], packs[4], packs[5] ]
107+
108+
const complete = lib.Pathfinder.isComplete(path)
109+
110+
const t1 = process.hrtime(t0)
111+
const t = t1[1] / 1e6
112+
113+
assert(t < 5, `actual time: ${t} ms`)
114+
assert(!complete)
115+
})
116+
it('should execute in under 2ms (n=4, no errors)', () => {
117+
const t0 = process.hrtime()
118+
const path = [ packs[0], packs[1], packs[2], packs[3] ]
119+
120+
const complete = lib.Pathfinder.isComplete(path)
121+
122+
const t1 = process.hrtime(t0)
123+
const t = t1[1] / 1e6
124+
125+
assert(t < 2, `actual time: ${t} ms`)
126+
assert(complete)
127+
})
128+
})
129+
})
130+
})
131+

test-performance/mocha.opts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--reporter spec
2+
--recursive
3+
--full-trace
4+
--no-exit
5+
--check-leaks
6+
--globals app

test-performance/testapp.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const smokesignals = require('smokesignals')
2+
3+
module.exports = {
4+
api: {
5+
6+
},
7+
config: {
8+
main: {
9+
paths: {
10+
root: __dirname
11+
}
12+
},
13+
log: {
14+
logger: new smokesignals.Logger('silent')
15+
}
16+
},
17+
pkg: {
18+
19+
}
20+
}

test/lib/pathfinder.test.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -356,30 +356,6 @@ describe('lib.Pathfinder', () => {
356356
const valid = lib.Pathfinder.isComplete(path)
357357
assert(!valid)
358358
})
359-
it('should execute in under 5ms (n=6, with errors)', () => {
360-
const t0 = process.hrtime()
361-
const path = [ packs[0], packs[1], packs[2], packs[3], packs[4], packs[5] ]
362-
363-
const complete = lib.Pathfinder.isComplete(path)
364-
365-
const t1 = process.hrtime(t0)
366-
const t = t1[1] / 1e6
367-
368-
assert(t < 5, `actual time: ${t} ms`)
369-
assert(!complete)
370-
})
371-
it('should execute in under 2ms (n=4, no errors)', () => {
372-
const t0 = process.hrtime()
373-
const path = [ packs[0], packs[1], packs[2], packs[3] ]
374-
375-
const complete = lib.Pathfinder.isComplete(path)
376-
377-
const t1 = process.hrtime(t0)
378-
const t = t1[1] / 1e6
379-
380-
assert(t < 2, `actual time: ${t} ms`)
381-
assert(complete)
382-
})
383359
})
384360
})
385361
})

0 commit comments

Comments
 (0)