@@ -240,6 +240,154 @@ describe('Dynamic Instrumentation', function () {
240240 }
241241 } )
242242 }
243+
244+ describe ( 'multiple probes at the same location' , function ( ) {
245+ it ( 'should support adding multiple probes at the same location' , function ( done ) {
246+ const rcConfig1 = t . generateRemoteConfig ( )
247+ const rcConfig2 = t . generateRemoteConfig ( )
248+ const expectedPayloads = [ {
249+ ddsource : 'dd_debugger' ,
250+ service : 'node' ,
251+ debugger : { diagnostics : { probeId : rcConfig1 . config . id , probeVersion : 0 , status : 'RECEIVED' } }
252+ } , {
253+ ddsource : 'dd_debugger' ,
254+ service : 'node' ,
255+ debugger : { diagnostics : { probeId : rcConfig2 . config . id , probeVersion : 0 , status : 'RECEIVED' } }
256+ } , {
257+ ddsource : 'dd_debugger' ,
258+ service : 'node' ,
259+ debugger : { diagnostics : { probeId : rcConfig1 . config . id , probeVersion : 0 , status : 'INSTALLED' } }
260+ } , {
261+ ddsource : 'dd_debugger' ,
262+ service : 'node' ,
263+ debugger : { diagnostics : { probeId : rcConfig2 . config . id , probeVersion : 0 , status : 'INSTALLED' } }
264+ } ]
265+
266+ t . agent . on ( 'debugger-diagnostics' , ( { payload } ) => {
267+ payload . forEach ( ( event ) => {
268+ const expected = expectedPayloads . shift ( )
269+ assertObjectContains ( event , expected )
270+ } )
271+ endIfDone ( )
272+ } )
273+
274+ t . agent . addRemoteConfig ( rcConfig1 )
275+ t . agent . addRemoteConfig ( rcConfig2 )
276+
277+ function endIfDone ( ) {
278+ if ( expectedPayloads . length === 0 ) done ( )
279+ }
280+ } )
281+
282+ it ( 'should support triggering multiple probes added at the same location' , function ( done ) {
283+ let installed = 0
284+ const rcConfig1 = t . generateRemoteConfig ( )
285+ const rcConfig2 = t . generateRemoteConfig ( )
286+ const expectedPayloads = new Map ( [
287+ [ rcConfig1 . config . id , {
288+ ddsource : 'dd_debugger' ,
289+ service : 'node' ,
290+ debugger : { diagnostics : { probeId : rcConfig1 . config . id , probeVersion : 0 , status : 'EMITTING' } }
291+ } ] ,
292+ [ rcConfig2 . config . id , {
293+ ddsource : 'dd_debugger' ,
294+ service : 'node' ,
295+ debugger : { diagnostics : { probeId : rcConfig2 . config . id , probeVersion : 0 , status : 'EMITTING' } }
296+ } ]
297+ ] )
298+
299+ t . agent . on ( 'debugger-diagnostics' , ( { payload } ) => {
300+ payload . forEach ( ( event ) => {
301+ const { diagnostics } = event . debugger
302+ if ( diagnostics . status === 'INSTALLED' ) {
303+ if ( ++ installed === 2 ) {
304+ t . axios . get ( t . breakpoint . url ) . catch ( done )
305+ }
306+ } else if ( diagnostics . status === 'EMITTING' ) {
307+ const expected = expectedPayloads . get ( diagnostics . probeId )
308+ expectedPayloads . delete ( diagnostics . probeId )
309+ assertObjectContains ( event , expected )
310+ }
311+ } )
312+ endIfDone ( )
313+ } )
314+
315+ t . agent . addRemoteConfig ( rcConfig1 )
316+ t . agent . addRemoteConfig ( rcConfig2 )
317+
318+ function endIfDone ( ) {
319+ if ( expectedPayloads . size === 0 ) done ( )
320+ }
321+ } )
322+
323+ it ( 'should support not triggering any probes when all conditions are not met' , function ( done ) {
324+ let installed = 0
325+ const rcConfig1 = t . generateRemoteConfig ( { when : { json : { eq : [ { ref : 'foo' } , 'bar' ] } } } )
326+ const rcConfig2 = t . generateRemoteConfig ( { when : { json : { eq : [ { ref : 'foo' } , 'baz' ] } } } )
327+
328+ t . agent . on ( 'debugger-diagnostics' , ( { payload } ) => {
329+ payload . forEach ( ( event ) => {
330+ const { diagnostics } = event . debugger
331+ if ( diagnostics . status === 'INSTALLED' ) {
332+ if ( ++ installed === 2 ) {
333+ t . axios . get ( t . breakpoint . url ) . catch ( done )
334+ setTimeout ( done , 2000 )
335+ }
336+ } else if ( diagnostics . status === 'EMITTING' ) {
337+ assert . fail ( 'should not trigger any probes when all conditions are not met' )
338+ }
339+ } )
340+ } )
341+
342+ t . agent . addRemoteConfig ( rcConfig1 )
343+ t . agent . addRemoteConfig ( rcConfig2 )
344+ } )
345+
346+ it ( 'should support only triggering the probes whos conditions are met' , function ( done ) {
347+ let installed = 0
348+ const rcConfig1 = t . generateRemoteConfig ( { when : { json : { eq : [ { ref : 'foo' } , 'bar' ] } } } )
349+ const rcConfig2 = t . generateRemoteConfig ( {
350+ when : { json : { eq : [ { getmember : [ { getmember : [ { ref : 'request' } , 'params' ] } , 'name' ] } , 'bar' ] } }
351+ } )
352+ const rcConfig3 = t . generateRemoteConfig ( )
353+ const expectedPayloads = new Map ( [
354+ [ rcConfig2 . config . id , {
355+ ddsource : 'dd_debugger' ,
356+ service : 'node' ,
357+ debugger : { diagnostics : { probeId : rcConfig2 . config . id , probeVersion : 0 , status : 'EMITTING' } }
358+ } ] ,
359+ [ rcConfig3 . config . id , {
360+ ddsource : 'dd_debugger' ,
361+ service : 'node' ,
362+ debugger : { diagnostics : { probeId : rcConfig3 . config . id , probeVersion : 0 , status : 'EMITTING' } }
363+ } ]
364+ ] )
365+
366+ t . agent . on ( 'debugger-diagnostics' , ( { payload } ) => {
367+ payload . forEach ( ( event ) => {
368+ const { diagnostics } = event . debugger
369+ if ( diagnostics . status === 'INSTALLED' ) {
370+ if ( ++ installed === 3 ) {
371+ t . axios . get ( t . breakpoint . url ) . catch ( done )
372+ }
373+ } else if ( diagnostics . status === 'EMITTING' ) {
374+ const expected = expectedPayloads . get ( diagnostics . probeId )
375+ expectedPayloads . delete ( diagnostics . probeId )
376+ assertObjectContains ( event , expected )
377+ }
378+ } )
379+ endIfDone ( )
380+ } )
381+
382+ t . agent . addRemoteConfig ( rcConfig1 )
383+ t . agent . addRemoteConfig ( rcConfig2 )
384+ t . agent . addRemoteConfig ( rcConfig3 )
385+
386+ function endIfDone ( ) {
387+ if ( expectedPayloads . size === 0 ) done ( )
388+ }
389+ } )
390+ } )
243391 } )
244392
245393 describe ( 'input messages' , function ( ) {
@@ -395,7 +543,7 @@ describe('Dynamic Instrumentation', function () {
395543 beforeEach ( t . triggerBreakpoint )
396544
397545 it ( 'should trigger when condition is met' , function ( done ) {
398- t . agent . on ( 'debugger-input' , ( x ) => {
546+ t . agent . on ( 'debugger-input' , ( ) => {
399547 done ( )
400548 } )
401549
0 commit comments