Skip to content

Commit c902265

Browse files
DavidCai1111MylesBorins
authored andcommitted
test: fix parallel/test-setproctitle.js on alpine
Since Busybox ps does not support -p switch, using ps -o and grep instead to get the process title and then check it. Backport-PR-URL: #13072 PR-URL: #12413 Fixes: #12399 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
1 parent 7bda962 commit c902265

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/parallel/test-setproctitle.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ const path = require('path');
1414
// The title shouldn't be too long; libuv's uv_set_process_title() out of
1515
// security considerations no longer overwrites envp, only argv, so the
1616
// maximum title length is possibly quite short.
17-
let title = 'testme';
17+
let title = 'test';
1818

1919
assert.notStrictEqual(process.title, title);
2020
process.title = title;
2121
assert.strictEqual(process.title, title);
2222

23-
exec(`ps -p ${process.pid} -o args=`, function callback(error, stdout, stderr) {
23+
// To pass this test on alpine, since Busybox `ps` does not
24+
// support `-p` switch, use `ps -o` and `grep` instead.
25+
const cmd = common.isLinux ?
26+
`ps -o pid,args | grep '${process.pid} ${title}' | grep -v grep` :
27+
`ps -p ${process.pid} -o args=`;
28+
29+
exec(cmd, common.mustCall((error, stdout, stderr) => {
2430
assert.ifError(error);
2531
assert.strictEqual(stderr, '');
2632

@@ -29,5 +35,5 @@ exec(`ps -p ${process.pid} -o args=`, function callback(error, stdout, stderr) {
2935
title += ` (${path.basename(process.execPath)})`;
3036

3137
// omitting trailing whitespace and \n
32-
assert.strictEqual(stdout.replace(/\s+$/, ''), title);
33-
});
38+
assert.strictEqual(stdout.replace(/\s+$/, '').endsWith(title), true);
39+
}));

0 commit comments

Comments
 (0)