Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix timing sensitivity in debugger test #11008

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions test/parallel/test-debugger-util-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const path = require('path');
const spawn = require('child_process').spawn;
const assert = require('assert');

const DELAY = common.platformTimeout(200);

const fixture = path.join(
common.fixturesDir,
'debugger-util-regression-fixture.js'
Expand All @@ -21,12 +23,16 @@ proc.stderr.setEncoding('utf8');

let stdout = '';
let stderr = '';
proc.stdout.on('data', (data) => stdout += data);
proc.stderr.on('data', (data) => stderr += data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think proc.stdout.setEncoding('utf-8') would be good practice here (and the same for proc.stderr)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's already there, a few lines above, unchanged by my patch.


let nextCount = 0;
let exit = false;

proc.stdout.on('data', (data) => {
stdout += data;
// We look at output periodically. We don't do this in the on('data') as we
// 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 ||
stdout.includes('> 2') && nextCount < 2 ||
stdout.includes('> 3') && nextCount < 3 ||
Expand All @@ -36,14 +42,14 @@ proc.stdout.on('data', (data) => {
} else if (!exit && (stdout.includes('< { a: \'b\' }'))) {
exit = true;
proc.stdin.write('.exit\n');
// We can cancel the timer and terminate normally.
clearInterval(timer);
} else if (stdout.includes('program terminated')) {
// Catch edge case present in v4.x
// process will terminate after call to util.inspect
common.fail('the program should not terminate');
}
});

proc.stderr.on('data', (data) => stderr += data);
}, DELAY);

process.on('exit', (code) => {
assert.strictEqual(code, 0, 'the program should exit cleanly');
Expand Down