mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-08 18:31:43 +00:00
test: add browse instrumentation helpers
This commit is contained in:
parent
6d3773a0b8
commit
c55361c552
3 changed files with 127 additions and 4 deletions
54
test/server/utils/libraryBrowseInstrumentation.test.js
Normal file
54
test/server/utils/libraryBrowseInstrumentation.test.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
const chai = require('chai')
|
||||
const expect = chai.expect
|
||||
|
||||
const {
|
||||
createBrowseRequestProfile,
|
||||
finishBrowseRequestProfile
|
||||
} = require('../../../server/utils/queries/libraryBrowseInstrumentation')
|
||||
|
||||
describe('libraryBrowseInstrumentation', () => {
|
||||
it('records named browse phases and returns a slow-summary payload', () => {
|
||||
const timestamps = [
|
||||
100,
|
||||
110,
|
||||
160,
|
||||
170,
|
||||
200,
|
||||
210,
|
||||
235,
|
||||
240,
|
||||
280,
|
||||
320
|
||||
]
|
||||
|
||||
const profile = createBrowseRequestProfile({
|
||||
route: 'GET /api/libraries/:id/items',
|
||||
libraryId: 'lib_1',
|
||||
now: () => timestamps.shift()
|
||||
})
|
||||
|
||||
profile.mark('rows:start')
|
||||
profile.mark('rows:end')
|
||||
profile.mark('count:start')
|
||||
profile.mark('count:end')
|
||||
profile.mark('derived:start')
|
||||
profile.mark('derived:end')
|
||||
profile.mark('postprocess:start')
|
||||
profile.mark('postprocess:end')
|
||||
|
||||
const result = finishBrowseRequestProfile(profile, { slowMs: 150 })
|
||||
|
||||
expect(result).to.deep.equal({
|
||||
route: 'GET /api/libraries/:id/items',
|
||||
libraryId: 'lib_1',
|
||||
totalMs: 220,
|
||||
phases: {
|
||||
rows: 50,
|
||||
count: 30,
|
||||
derived: 25,
|
||||
postprocess: 40
|
||||
},
|
||||
isSlow: true
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue