Skip to content

Commit b2cf6ed

Browse files
authored
test: Fixed fastify segment tree assertion when security agent is enabled (newrelic#3422)
1 parent 04af258 commit b2cf6ed

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

test/versioned/fastify/add-hook.test.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ test('non-error hooks', async (t) => {
9595
'WebTransaction/WebFrameworkUri/Fastify/GET//add-hook',
9696
[
9797
'Nodejs/Middleware/Fastify/onRequest/<anonymous>',
98-
[
99-
...getExpectedSegments(REQUEST_HOOKS),
100-
'Nodejs/Middleware/Fastify/routeHandler//add-hook',
101-
getExpectedSegments(AFTER_HANDLER_HOOKS)
102-
]
98+
...getExpectedSegments(REQUEST_HOOKS),
99+
'Nodejs/Middleware/Fastify/routeHandler//add-hook',
100+
getExpectedSegments(AFTER_HANDLER_HOOKS)
103101
]
104102
]
105103
} else {
@@ -155,10 +153,8 @@ test('error hook', async function errorHookTest(t) {
155153
'WebTransaction/WebFrameworkUri/Fastify/GET//error',
156154
[
157155
'Nodejs/Middleware/Fastify/onRequest/<anonymous>',
158-
[
159-
'Nodejs/Middleware/Fastify/errorRoute//error',
160-
`Nodejs/Middleware/Fastify/${hookName}/testHook`
161-
]
156+
'Nodejs/Middleware/Fastify/errorRoute//error',
157+
`Nodejs/Middleware/Fastify/${hookName}/testHook`
162158
]
163159
]
164160
} else {

test/versioned/fastify/code-level-metrics-hooks.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ async function performTest(t) {
4646
const [baseSegment] = transaction.trace.getChildren(transaction.trace.root.id)
4747
let [onRequestSegment, handlerSegment] = transaction.trace.getChildren(baseSegment.id)
4848
if (helper.isSecurityAgentEnabled(agent)) {
49-
;[onRequestSegment, handlerSegment] = transaction.trace.getChildren(onRequestSegment.id)
49+
;[, onRequestSegment, handlerSegment] = transaction.trace.getChildren(baseSegment.id)
5050
}
51+
5152
const [onSendSegment] = transaction.trace.getChildren(handlerSegment.id)
5253
assertCLMAttrs({
5354
segments: [

test/versioned/fastify/code-level-metrics-middleware.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ async function setup(t, config) {
4949

5050
function assertSegments({ t, trace, baseSegment, isCLMEnabled }) {
5151
const { agent } = t.nr
52-
let children = trace.getChildren(baseSegment.id)
52+
const children = trace.getChildren(baseSegment.id)
53+
let [middieSegment, handlerSegment] = children
5354
if (helper.isSecurityAgentEnabled(agent)) {
54-
children = trace.getChildren(children[0].id)
55+
;[, middieSegment, handlerSegment] = children
5556
}
56-
const [middieSegment, handlerSegment] = children
5757
assertCLMAttrs({
5858
segments: [
5959
{

test/versioned/fastify/naming-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = async function runTests(t, getExpectedSegments) {
3434
// it sometimes has timers.setTimeout depending on route
3535
expectedSegments = [
3636
`WebTransaction/WebFrameworkUri/Fastify/GET/${uri}`,
37-
['Nodejs/Middleware/Fastify/onRequest/<anonymous>', getExpectedSegments(uri)]
37+
['Nodejs/Middleware/Fastify/onRequest/<anonymous>', ...getExpectedSegments(uri)]
3838
]
3939
} else {
4040
expectedSegments = [

0 commit comments

Comments
 (0)