Description
As we migrate over our instrumentation to use the tracing channel, we need an easy and standard way to assert segment durations. So far different test suites do it a bit differently, but the closest one that could be used across packages is assertSegmentState in the memcached versioned tests:
|
/** |
|
* Asserts that the current segment has the expected name, has ended, |
|
* and has a duration within a reasonable threshold of the actual measured time. |
|
* @param {TraceSegment} segment segment to check |
|
* @param {string} expectedName expected segment name |
|
* @param {Array} actualTime process.hrtime() duration of the actual call |
|
*/ |
|
function assertSegmentState(segment, expectedName, actualTime) { |
|
assert.equal(segment.name, expectedName) |
|
assert.equal(segment._isEnded(), true, 'segment should have ended') |
|
const segmentDuration = segment.getDurationInMillis() |
|
const actualDuration = hrToMillis(actualTime) |
|
assert.ok( |
|
Math.abs(segmentDuration - actualDuration) < 1, |
|
`segment duration (${segmentDuration}ms) should be within 1ms of actual duration (${actualDuration}ms)` |
|
) |
|
} |
.
We need to create this function in custom-assertions and implement it across our test suites. Instead of a strict 1ms (or similar constant) threshold, we should use a percentage threshold.
Acceptance Criteria
Description
As we migrate over our instrumentation to use the tracing channel, we need an easy and standard way to assert segment durations. So far different test suites do it a bit differently, but the closest one that could be used across packages is
assertSegmentStatein thememcachedversioned tests:node-newrelic/test/versioned/memcached/memcached.test.js
Lines 1034 to 1050 in 915b320
We need to create this function in
custom-assertionsand implement it across our test suites. Instead of a strict1ms(or similar constant) threshold, we should use a percentage threshold.Acceptance Criteria
sleep(2)inmysql2) use this new function and they still pass