@@ -9,6 +9,7 @@ const helper = require('../../lib/agent_helper')
99const test = require ( 'node:test' )
1010const assert = require ( 'node:assert' )
1111const symbols = require ( '../../../lib/symbols' )
12+ const nock = require ( 'nock' )
1213
1314test ( 'external requests' , async function ( t ) {
1415 t . beforeEach ( ( ctx ) => {
@@ -102,10 +103,15 @@ test('external requests', async function (t) {
102103 let connectChildren = tx . trace . getChildren ( connect . id )
103104 assert . equal ( connectChildren . length , 1 , 'connect should have 1 child' )
104105
106+ // as of Node 24.5.0 there's yet another layer of net segments
107+ if ( connectChildren [ 0 ] . name === 'net.createConnection' ) {
108+ connectChildren = tx . trace . getChildren ( connectChildren [ 0 ] . id )
109+ }
105110 // There is potentially an extra layer of create/connect segments.
106111 if ( connectChildren [ 0 ] . name === 'net.Socket.connect' ) {
107112 connect = connectChildren [ 0 ]
108113 }
114+
109115 connectChildren = tx . trace . getChildren ( connect . id )
110116
111117 const dnsLookup = connectChildren [ 0 ]
@@ -159,42 +165,15 @@ test('external requests', async function (t) {
159165 } )
160166 } )
161167
162- await t . test ( 'should not duplicate the external segment' , function ( t , end ) {
163- const { agent } = t . nr
164- const https = require ( 'https' )
165-
166- helper . runInTransaction ( agent , function inTransaction ( ) {
167- https . get ( 'https://example.com:443/' , function onResponse ( res ) {
168- res . once ( 'end' , check )
169- res . resume ( )
170- } )
171- } )
172-
173- function check ( ) {
174- const tx = agent . getTransaction ( )
175- const [ segment ] = tx . trace . getChildren ( tx . trace . root . id )
176-
177- assert . equal ( segment . name , 'External/example.com/' , 'should be named' )
178- assert . ok ( segment . timer . start , 'should have started' )
179- assert . ok ( segment . timer . hasEnd ( ) , 'should have ended' )
180- const segmentChildren = tx . trace . getChildren ( segment . id )
181- assert . equal ( segmentChildren . length , 1 , 'should have 1 child' )
182-
183- const notDuped = segmentChildren [ 0 ]
184- assert . notEqual (
185- notDuped . name ,
186- segment . name ,
187- 'child should not be named the same as the external segment'
188- )
189-
190- end ( )
191- }
192- } )
193-
194168 await t . test ( 'NODE-1647 should not interfere with `got`' , { timeout : 5000 } , function ( t , end ) {
195169 const { agent } = t . nr
196170 // Our way of wrapping HTTP response objects caused `got` to hang. This was
197171 // resolved in agent 2.5.1.
172+ nock . disableNetConnect ( )
173+ t . after ( ( ) => {
174+ nock . enableNetConnect ( )
175+ } )
176+ nock ( 'https://example.com' ) . get ( '/' ) . reply ( 200 )
198177 const got = require ( 'got' )
199178 helper . runInTransaction ( agent , function ( ) {
200179 const req = got ( 'https://example.com/' )
@@ -215,8 +194,13 @@ test('external requests', async function (t) {
215194
216195 await t . test ( 'should record requests to default ports' , ( t , end ) => {
217196 const { agent, http } = t . nr
197+ nock . disableNetConnect ( )
198+ t . after ( ( ) => {
199+ nock . enableNetConnect ( )
200+ } )
201+ nock ( 'http://example.com' ) . get ( '/' ) . reply ( 200 )
218202 helper . runInTransaction ( agent , ( tx ) => {
219- http . get ( 'http://example.com' , ( res ) => {
203+ http . get ( 'http://example.com/ ' , ( res ) => {
220204 res . resume ( )
221205 res . on ( 'end' , ( ) => {
222206 const [ segment ] = tx . trace . getChildren ( tx . trace . root . id )
@@ -229,9 +213,14 @@ test('external requests', async function (t) {
229213
230214 await t . test ( 'should expose the external segment on the http request' , ( t , end ) => {
231215 const { agent, http } = t . nr
216+ nock . disableNetConnect ( )
217+ t . after ( ( ) => {
218+ nock . enableNetConnect ( )
219+ } )
220+ nock ( 'http://example.com' ) . get ( '/' ) . reply ( 200 )
232221 helper . runInTransaction ( agent , ( tx ) => {
233222 let reqSegment = null
234- const req = http . get ( 'http://example.com' , ( res ) => {
223+ const req = http . get ( 'http://example.com/ ' , ( res ) => {
235224 res . resume ( )
236225 res . on ( 'end' , ( ) => {
237226 const [ segment ] = tx . trace . getChildren ( tx . trace . root . id )
0 commit comments