@@ -14,7 +14,7 @@ describe('Dynamic Instrumentation', function () {
14
14
it ( 'base case: target app should work as expected if no test probe has been added' , async function ( ) {
15
15
const response = await t . axios . get ( t . breakpoint . url )
16
16
assert . strictEqual ( response . status , 200 )
17
- assert . deepStrictEqual ( response . data , { hello : 'foo ' } )
17
+ assert . deepStrictEqual ( response . data , { hello : 'bar ' } )
18
18
} )
19
19
20
20
describe ( 'diagnostics messages' , function ( ) {
@@ -54,7 +54,7 @@ describe('Dynamic Instrumentation', function () {
54
54
t . axios . get ( t . breakpoint . url )
55
55
. then ( ( response ) => {
56
56
assert . strictEqual ( response . status , 200 )
57
- assert . deepStrictEqual ( response . data , { hello : 'foo ' } )
57
+ assert . deepStrictEqual ( response . data , { hello : 'bar ' } )
58
58
} )
59
59
. catch ( done )
60
60
} else {
@@ -245,7 +245,7 @@ describe('Dynamic Instrumentation', function () {
245
245
message : 'Hello World!' ,
246
246
logger : {
247
247
name : t . breakpoint . file ,
248
- method : 'handler ' ,
248
+ method : 'fooHandler ' ,
249
249
version,
250
250
thread_name : 'MainThread'
251
251
} ,
@@ -279,7 +279,7 @@ describe('Dynamic Instrumentation', function () {
279
279
const topFrame = payload [ 'debugger.snapshot' ] . stack [ 0 ]
280
280
// path seems to be prefeixed with `/private` on Mac
281
281
assert . match ( topFrame . fileName , new RegExp ( `${ t . appFile } $` ) )
282
- assert . strictEqual ( topFrame . function , 'handler ' )
282
+ assert . strictEqual ( topFrame . function , 'fooHandler ' )
283
283
assert . strictEqual ( topFrame . lineNumber , t . breakpoint . line )
284
284
assert . strictEqual ( topFrame . columnNumber , 3 )
285
285
@@ -375,6 +375,61 @@ describe('Dynamic Instrumentation', function () {
375
375
376
376
t . agent . addRemoteConfig ( rcConfig )
377
377
} )
378
+
379
+ it ( 'should adhere to individual probes sample rate' , function ( done ) {
380
+ const rcConfig1 = t . breakpoints [ 0 ] . generateRemoteConfig ( { sampling : { snapshotsPerSecond : 1 } } )
381
+ const rcConfig2 = t . breakpoints [ 1 ] . generateRemoteConfig ( { sampling : { snapshotsPerSecond : 1 } } )
382
+ const state = {
383
+ [ rcConfig1 . config . id ] : {
384
+ payloadsReceived : 0 ,
385
+ tiggerBreakpointContinuously ( ) {
386
+ t . axios . get ( t . breakpoints [ 0 ] . url ) . catch ( done )
387
+ this . timer = setTimeout ( this . tiggerBreakpointContinuously . bind ( this ) , 10 )
388
+ }
389
+ } ,
390
+ [ rcConfig2 . config . id ] : {
391
+ payloadsReceived : 0 ,
392
+ tiggerBreakpointContinuously ( ) {
393
+ t . axios . get ( t . breakpoints [ 1 ] . url ) . catch ( done )
394
+ this . timer = setTimeout ( this . tiggerBreakpointContinuously . bind ( this ) , 10 )
395
+ }
396
+ }
397
+ }
398
+
399
+ t . agent . on ( 'debugger-diagnostics' , ( { payload } ) => {
400
+ const { probeId, status } = payload . debugger . diagnostics
401
+ if ( status === 'INSTALLED' ) state [ probeId ] . tiggerBreakpointContinuously ( )
402
+ } )
403
+
404
+ t . agent . on ( 'debugger-input' , ( { payload } ) => {
405
+ const _state = state [ payload [ 'debugger.snapshot' ] . probe . id ]
406
+ _state . payloadsReceived ++
407
+ if ( _state . payloadsReceived === 1 ) {
408
+ _state . start = Date . now ( )
409
+ } else if ( _state . payloadsReceived === 2 ) {
410
+ const duration = Date . now ( ) - _state . start
411
+ clearTimeout ( _state . timer )
412
+
413
+ // Allow for a variance of -5/+50ms (time will tell if this is enough)
414
+ assert . isAbove ( duration , 995 )
415
+ assert . isBelow ( duration , 1050 )
416
+
417
+ // Wait at least a full sampling period, to see if we get any more payloads
418
+ _state . timer = setTimeout ( doneWhenCalledTwice , 1250 )
419
+ } else {
420
+ clearTimeout ( _state . timer )
421
+ done ( new Error ( 'Too many payloads received!' ) )
422
+ }
423
+ } )
424
+
425
+ t . agent . addRemoteConfig ( rcConfig1 )
426
+ t . agent . addRemoteConfig ( rcConfig2 )
427
+
428
+ function doneWhenCalledTwice ( ) {
429
+ if ( doneWhenCalledTwice . calledOnce ) return done ( )
430
+ doneWhenCalledTwice . calledOnce = true
431
+ }
432
+ } )
378
433
} )
379
434
380
435
describe ( 'race conditions' , function ( ) {
0 commit comments