|
3 | 3 | const assert = require('node:assert') |
4 | 4 | const { setup } = require('./utils') |
5 | 5 |
|
6 | | -describe('Dynamic Instrumentation', function () { |
7 | | - // Force a very small time budget in ms to trigger partial snapshots |
8 | | - const t = setup({ |
9 | | - dependencies: ['fastify'], |
10 | | - env: { DD_DYNAMIC_INSTRUMENTATION_CAPTURE_TIMEOUT_MS: '1' } |
11 | | - }) |
| 6 | +const tolerance = 5 |
12 | 7 |
|
| 8 | +describe('Dynamic Instrumentation', function () { |
13 | 9 | describe('input messages', function () { |
14 | 10 | describe('with snapshot under tight time budget', function () { |
15 | | - beforeEach(t.triggerBreakpoint) |
16 | | - |
17 | | - it('should include partial snapshot marked with notCapturedReason: timeout', function (done) { |
18 | | - t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => { |
19 | | - const { locals } = captures.lines[t.breakpoint.line] |
20 | | - assert.strictEqual( |
21 | | - containsTimeBudget(locals), |
22 | | - true, |
23 | | - 'expected at least one field/element to be marked with notCapturedReason: "timeout"' |
24 | | - ) |
25 | | - done() |
| 11 | + context('1ms time budget', function () { |
| 12 | + // Force a very small time budget in ms to trigger partial snapshots |
| 13 | + const target = 1 |
| 14 | + const t = setup({ |
| 15 | + dependencies: ['fastify'], |
| 16 | + env: { DD_DYNAMIC_INSTRUMENTATION_CAPTURE_TIMEOUT_MS: String(target) } |
26 | 17 | }) |
27 | 18 |
|
28 | | - t.agent.addRemoteConfig(t.generateRemoteConfig({ |
29 | | - captureSnapshot: true, |
30 | | - capture: { maxReferenceDepth: 5 } |
31 | | - })) |
| 19 | + it( |
| 20 | + 'should include partial snapshot marked with notCapturedReason: timeout', |
| 21 | + test({ t, maxPausedTime: target + tolerance, breakpointIndex: 0, maxReferenceDepth: 5 }) |
| 22 | + ) |
| 23 | + }) |
| 24 | + |
| 25 | + context('default time budget', function () { |
| 26 | + const target = 10 // default time budget in ms |
| 27 | + const t = setup({ dependencies: ['fastify'] }) |
| 28 | + |
| 29 | + // TODO: Make this pass |
| 30 | + // eslint-disable-next-line mocha/no-pending-tests |
| 31 | + it.skip( |
| 32 | + 'should keep budget when state includes an object with 1 million properties', |
| 33 | + test({ t, maxPausedTime: target + tolerance, breakpointIndex: 1, maxReferenceDepth: 1 }) |
| 34 | + ) |
| 35 | + |
| 36 | + // TODO: Make this pass |
| 37 | + // eslint-disable-next-line mocha/no-pending-tests |
| 38 | + it.skip( |
| 39 | + 'should keep budget when state includes an array of 1 million primitives', |
| 40 | + test({ t, maxPausedTime: target + tolerance, breakpointIndex: 2, maxReferenceDepth: 1 }) |
| 41 | + ) |
| 42 | + |
| 43 | + // TODO: Make this pass |
| 44 | + // eslint-disable-next-line mocha/no-pending-tests |
| 45 | + it.skip( |
| 46 | + 'should keep budget when state includes an array of 1 million objects', |
| 47 | + test({ t, maxPausedTime: target + tolerance, breakpointIndex: 3, maxReferenceDepth: 1 }) |
| 48 | + ) |
32 | 49 | }) |
33 | 50 | }) |
34 | 51 | }) |
35 | 52 | }) |
36 | 53 |
|
| 54 | +function test ({ t, maxPausedTime, breakpointIndex, maxReferenceDepth }) { |
| 55 | + const breakpoint = t.breakpoints[breakpointIndex] |
| 56 | + |
| 57 | + return async function () { |
| 58 | + const payloadReceived = new Promise((/** @type {(value?: unknown) => void} */ resolve) => { |
| 59 | + t.agent.on('debugger-input', ({ payload: [{ debugger: { snapshot: { captures } } }] }) => { |
| 60 | + const { locals } = captures.lines[breakpoint.line] |
| 61 | + assert.strictEqual( |
| 62 | + containsTimeBudget(locals), |
| 63 | + true, |
| 64 | + 'expected at least one field/element to be marked with notCapturedReason: "timeout"' |
| 65 | + ) |
| 66 | + resolve() |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + t.agent.addRemoteConfig(breakpoint.generateRemoteConfig({ |
| 71 | + captureSnapshot: true, |
| 72 | + capture: { maxReferenceDepth } |
| 73 | + })) |
| 74 | + |
| 75 | + const { data } = await breakpoint.triggerBreakpoint() |
| 76 | + |
| 77 | + assert.ok( |
| 78 | + data.paused <= maxPausedTime, |
| 79 | + `expected thread to be paused <=${maxPausedTime}ms, but was paused for ~${data.paused}ms` |
| 80 | + ) |
| 81 | + |
| 82 | + await payloadReceived |
| 83 | + } |
| 84 | +} |
| 85 | + |
37 | 86 | function containsTimeBudget (node) { |
38 | 87 | if (node == null || typeof node !== 'object') return false |
39 | 88 | if (node.notCapturedReason === 'timeout') return true |
|
0 commit comments