mirror of https://github.com/nodejs/node.git
test: fix timing sensitivity in debugger test
test-debugger-util-regression.js was sensitive to timing, which seems to have changed enough with V8 5.7 to cause this test to fail. Fix the test to ensure we take debugger steps only at stable states instead of erroneously taking a step on a partially complete buffer. PR-URL: https://github.com/nodejs/node/pull/11008 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>pull/11126/head
parent
3e3bfc57d9
commit
21b05cd6cd
|
@ -4,6 +4,8 @@ const path = require('path');
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const DELAY = common.platformTimeout(200);
|
||||||
|
|
||||||
const fixture = path.join(
|
const fixture = path.join(
|
||||||
common.fixturesDir,
|
common.fixturesDir,
|
||||||
'debugger-util-regression-fixture.js'
|
'debugger-util-regression-fixture.js'
|
||||||
|
@ -21,12 +23,16 @@ proc.stderr.setEncoding('utf8');
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
|
proc.stdout.on('data', (data) => stdout += data);
|
||||||
|
proc.stderr.on('data', (data) => stderr += data);
|
||||||
|
|
||||||
let nextCount = 0;
|
let nextCount = 0;
|
||||||
let exit = false;
|
let exit = false;
|
||||||
|
|
||||||
proc.stdout.on('data', (data) => {
|
// We look at output periodically. We don't do this in the on('data') as we
|
||||||
stdout += data;
|
// may end up processing partial output. Processing periodically ensures that
|
||||||
|
// the debugger is in a stable state before we take the next step.
|
||||||
|
const timer = setInterval(() => {
|
||||||
if (stdout.includes('> 1') && nextCount < 1 ||
|
if (stdout.includes('> 1') && nextCount < 1 ||
|
||||||
stdout.includes('> 2') && nextCount < 2 ||
|
stdout.includes('> 2') && nextCount < 2 ||
|
||||||
stdout.includes('> 3') && nextCount < 3 ||
|
stdout.includes('> 3') && nextCount < 3 ||
|
||||||
|
@ -36,14 +42,14 @@ proc.stdout.on('data', (data) => {
|
||||||
} else if (!exit && (stdout.includes('< { a: \'b\' }'))) {
|
} else if (!exit && (stdout.includes('< { a: \'b\' }'))) {
|
||||||
exit = true;
|
exit = true;
|
||||||
proc.stdin.write('.exit\n');
|
proc.stdin.write('.exit\n');
|
||||||
|
// We can cancel the timer and terminate normally.
|
||||||
|
clearInterval(timer);
|
||||||
} else if (stdout.includes('program terminated')) {
|
} else if (stdout.includes('program terminated')) {
|
||||||
// Catch edge case present in v4.x
|
// Catch edge case present in v4.x
|
||||||
// process will terminate after call to util.inspect
|
// process will terminate after call to util.inspect
|
||||||
common.fail('the program should not terminate');
|
common.fail('the program should not terminate');
|
||||||
}
|
}
|
||||||
});
|
}, DELAY);
|
||||||
|
|
||||||
proc.stderr.on('data', (data) => stderr += data);
|
|
||||||
|
|
||||||
process.on('exit', (code) => {
|
process.on('exit', (code) => {
|
||||||
assert.strictEqual(code, 0, 'the program should exit cleanly');
|
assert.strictEqual(code, 0, 'the program should exit cleanly');
|
||||||
|
|
Loading…
Reference in New Issue