node-servertiming
node-servertiming copied to clipboard
Multiple ServerTiming instances should not share label(s)
I think it is confusing that each label has to be distinct across multiple instances of ServerTiming.
Steps to reproduce
'use strict'
const ServerTiming = require('servertiming')
function time (label, promise) {
return new Promise ((resolve, reject) => {
const timing = new ServerTiming()
timing.startTimer (label)
promise.then(value => {
timing.stopTimer (label)
resolve ([value, {"Server-Timing":timing.generateHeader()}])
})
})
}
function heavyComputation (value) {
return new Promise ((resolve, reject) => {
setTimeout (() => {
resolve (value)
}, 500)
})
}
Promise.all([
time('Multiple ServerTiming instances should not share labels', heavyComputation(1)),
time('Multiple ServerTiming instances should not share labels', heavyComputation(2)),
time('Multiple ServerTiming instances should not share labels', heavyComputation(3)),
])
.then(timings => {
timings.map(([value, header]) => console.log(value, header['Server-Timing']))
})
.catch (console.error)
The above will output:
1 multiple-servertiming-instances-should-not-share-labels; dur=500.8789; desc="Multiple ServerTiming instances should not share labels"
2 multiple-servertiming-instances-should-not-share-labels; dur=0; desc="Multiple ServerTiming instances should not share labels"
3 multiple-servertiming-instances-should-not-share-labels; dur=0; desc="Multiple ServerTiming instances should not share labels"
Obviously the duration is not correct.
node-servertiming: 1.5.0 node: v14.16.1