GeezerVison is showing github.com — test: normalize known inspector crash as completion · nodejs/node@da4dd86
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/debugger-probe.js +39-3Lines changed: 39 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 |
| | 3 | +const assert = require('assert'); | 3 | 4 | const fixtures = require('./fixtures'); | 4 | 5 | const path = require('path'); | 5 | 6 |
| 6 | 7 | function debuggerFixturePath(name) { | 7 | 8 | return path.relative(process.cwd(), fixtures.path('debugger', name)); | 8 | 9 | } | 9 | 10 |
| 10 | | -function escapeRegex(string) { | 11 | | - return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); | | 11 | +// Work around a pre-existing inspector issue: if the debuggee exits too quickly | | 12 | +// the inspector can segfault while tearing down. For now normalize the segfault | | 13 | +// back to the expected terminal event (e.g. "completed" or "miss") | | 14 | +// until the upstream bug is fixed. | | 15 | +// See https://github.com/nodejs/node/issues/62765 | | 16 | +// https://github.com/nodejs/node/issues/58245 | | 17 | +const probeTargetExitSignal = 'SIGSEGV'; | | 18 | + | | 19 | +function assertProbeJson(output, expected) { | | 20 | + const normalized = JSON.parse(output); | | 21 | + const lastResult = normalized.results?.[normalized.results.length - 1]; | | 22 | + | | 23 | + if (lastResult?.event === 'error' && | | 24 | + lastResult.error?.code === 'probe_target_exit' && | | 25 | + lastResult.error?.signal === probeTargetExitSignal) { | | 26 | + // Log to facilitate debugging if this normalization is occurring. | | 27 | + console.log('Normalizing trailing SIGSEGV in JSON probe output'); | | 28 | + normalized.results[normalized.results.length - 1] = expected.results.at(-1); | | 29 | + } | | 30 | + | | 31 | + assert.deepStrictEqual(normalized, expected); | | 32 | +} | | 33 | + | | 34 | +function assertProbeText(output, expected) { | | 35 | + const signalPrefix = `Target exited with signal ${probeTargetExitSignal}`; | | 36 | + const idx = output.indexOf(signalPrefix); | | 37 | + let normalized; | | 38 | + if (idx !== -1) { | | 39 | + // Log to facilitate debugging if this normalization is occurring. | | 40 | + console.log('Normalizing trailing SIGSEGV in text probe output'); | | 41 | + const lineStart = output.lastIndexOf('\n', idx); | | 42 | + normalized = (lineStart === -1 ? '' : output.slice(0, lineStart)) + '\nCompleted'; | | 43 | + } else { | | 44 | + normalized = output; | | 45 | + } | | 46 | + assert.strictEqual(normalized, expected); | 12 | 47 | } | 13 | 48 |
| 14 | 49 | module.exports = { | 15 | | - escapeRegex, | | 50 | + assertProbeJson, | | 51 | + assertProbeText, | 16 | 52 | missScript: debuggerFixturePath('probe-miss.js'), | 17 | 53 | probeScript: debuggerFixturePath('probe.js'), | 18 | 54 | throwScript: debuggerFixturePath('probe-throw.js'), | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-child-inspect-port-zero.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeScript } = require('../common/debugger-probe'); | | 8 | +const { assertProbeJson, probeScript } = require('../common/debugger-probe'); | 10 | 9 |
| 11 | 10 | spawnSyncAndAssert(process.execPath, [ | 12 | 11 | 'inspect', | @@ -18,7 +17,7 @@ spawnSyncAndAssert(process.execPath, [ | 18 | 17 | probeScript, | 19 | 18 | ], { | 20 | 19 | stdout(output) { | 21 | | - assert.deepStrictEqual(JSON.parse(output), { | | 20 | + assertProbeJson(output, { | 22 | 21 | v: 1, | 23 | 22 | probes: [{ | 24 | 23 | expr: 'finalValue', | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-global-option-order.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeScript } = require('../common/debugger-probe'); | | 8 | +const { assertProbeJson, probeScript } = require('../common/debugger-probe'); | 10 | 9 |
| 11 | 10 | spawnSyncAndAssert(process.execPath, [ | 12 | 11 | 'inspect', | @@ -16,7 +15,7 @@ spawnSyncAndAssert(process.execPath, [ | 16 | 15 | probeScript, | 17 | 16 | ], { | 18 | 17 | stdout(output) { | 19 | | - assert.deepStrictEqual(JSON.parse(output), { | | 18 | + assertProbeJson(output, { | 20 | 19 | v: 1, | 21 | 20 | probes: [{ | 22 | 21 | expr: 'finalValue', | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-json-preview.js +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeTypesScript } = require('../common/debugger-probe'); | | 8 | +const { | | 9 | + assertProbeJson, | | 10 | + probeTypesScript, | | 11 | +} = require('../common/debugger-probe'); | 10 | 12 |
| 11 | 13 | const location = `${probeTypesScript}:17`; | 12 | 14 |
| @@ -23,7 +25,7 @@ spawnSyncAndAssert(process.execPath, [ | 23 | 25 | probeTypesScript, | 24 | 26 | ], { | 25 | 27 | stdout(output) { | 26 | | - assert.deepStrictEqual(JSON.parse(output), { | | 28 | + assertProbeJson(output, { | 27 | 29 | v: 1, | 28 | 30 | probes: [ | 29 | 31 | { expr: 'objectValue', target: [probeTypesScript, 17] }, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-json-special-values.js +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeTypesScript } = require('../common/debugger-probe'); | | 8 | +const { | | 9 | + assertProbeJson, | | 10 | + probeTypesScript, | | 11 | +} = require('../common/debugger-probe'); | 10 | 12 |
| 11 | 13 | const location = `${probeTypesScript}:17`; | 12 | 14 |
| @@ -38,7 +40,7 @@ spawnSyncAndAssert(process.execPath, [ | 38 | 40 | probeTypesScript, | 39 | 41 | ], { | 40 | 42 | stdout(output) { | 41 | | - assert.deepStrictEqual(JSON.parse(output), { | | 43 | + assertProbeJson(output, { | 42 | 44 | v: 1, | 43 | 45 | probes: [ | 44 | 46 | { expr: 'stringValue', target: [probeTypesScript, 17] }, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-json.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeScript } = require('../common/debugger-probe'); | | 8 | +const { assertProbeJson, probeScript } = require('../common/debugger-probe'); | 10 | 9 |
| 11 | 10 | spawnSyncAndAssert(process.execPath, [ | 12 | 11 | 'inspect', | @@ -20,7 +19,7 @@ spawnSyncAndAssert(process.execPath, [ | 20 | 19 | probeScript, | 21 | 20 | ], { | 22 | 21 | stdout(output) { | 23 | | - assert.deepStrictEqual(JSON.parse(output), { | | 22 | + assertProbeJson(output, { | 24 | 23 | v: 1, | 25 | 24 | probes: [ | 26 | 25 | { expr: 'index', target: [probeScript, 8] }, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-miss.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { missScript } = require('../common/debugger-probe'); | | 8 | +const { assertProbeJson, missScript } = require('../common/debugger-probe'); | 10 | 9 |
| 11 | 10 | spawnSyncAndAssert(process.execPath, [ | 12 | 11 | 'inspect', | @@ -16,7 +15,7 @@ spawnSyncAndAssert(process.execPath, [ | 16 | 15 | missScript, | 17 | 16 | ], { | 18 | 17 | stdout(output) { | 19 | | - assert.deepStrictEqual(JSON.parse(output), { | | 18 | + assertProbeJson(output, { | 20 | 19 | v: 1, | 21 | 20 | probes: [{ expr: '42', target: [missScript, 99] }], | 22 | 21 | results: [{ | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-text-special-values.js +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeTypesScript } = require('../common/debugger-probe'); | | 8 | +const { | | 9 | + assertProbeText, | | 10 | + probeTypesScript, | | 11 | +} = require('../common/debugger-probe'); | 10 | 12 |
| 11 | 13 | const location = `${probeTypesScript}:17`; | 12 | 14 |
| @@ -37,7 +39,7 @@ spawnSyncAndAssert(process.execPath, [ | 37 | 39 | probeTypesScript, | 38 | 40 | ], { | 39 | 41 | stdout(output) { | 40 | | - assert.strictEqual(output, [ | | 42 | + assertProbeText(output, [ | 41 | 43 | `Hit 1 at ${location}`, | 42 | 44 | ' stringValue = "hello"', | 43 | 45 | `Hit 1 at ${location}`, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-text.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndAssert } = require('../common/child_process'); | 9 | | -const { probeScript } = require('../common/debugger-probe'); | | 8 | +const { assertProbeText, probeScript } = require('../common/debugger-probe'); | 10 | 9 |
| 11 | 10 | spawnSyncAndAssert(process.execPath, [ | 12 | 11 | 'inspect', | @@ -15,10 +14,10 @@ spawnSyncAndAssert(process.execPath, [ | 15 | 14 | probeScript, | 16 | 15 | ], { | 17 | 16 | stdout(output) { | 18 | | - assert.strictEqual(output, | 19 | | - `Hit 1 at ${probeScript}:12\n` + | 20 | | - ' finalValue = 81\n' + | 21 | | - 'Completed'); | | 17 | + assertProbeText(output, | | 18 | + `Hit 1 at ${probeScript}:12\n` + | | 19 | + ' finalValue = 81\n' + | | 20 | + 'Completed'); | 22 | 21 | }, | 23 | 22 | trim: true, | 24 | 23 | }); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-debugger-probe-timeout.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | const common = require('../common'); | 5 | 5 | common.skipIfInspectorDisabled(); | 6 | 6 |
| 7 | | -const assert = require('assert'); | 8 | 7 | const { spawnSyncAndExit } = require('../common/child_process'); | 9 | | -const { timeoutScript } = require('../common/debugger-probe'); | | 8 | +const { assertProbeJson, timeoutScript } = require('../common/debugger-probe'); | 10 | 9 |
| 11 | 10 | spawnSyncAndExit(process.execPath, [ | 12 | 11 | 'inspect', | @@ -19,7 +18,7 @@ spawnSyncAndExit(process.execPath, [ | 19 | 18 | signal: null, | 20 | 19 | status: 1, | 21 | 20 | stdout(output) { | 22 | | - assert.deepStrictEqual(JSON.parse(output), { | | 21 | + assertProbeJson(output, { | 23 | 22 | v: 1, | 24 | 23 | probes: [{ expr: '1', target: [timeoutScript, 99] }], | 25 | 24 | results: [{ | |
|