Skip to content

Commit 96b2faa

Browse files
DavidCai1111evanlucas
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. 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 e3ccc31 commit 96b2faa

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,7 +14,7 @@ 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;
@@ -25,7 +25,13 @@ if (common.isWindows) {
2525
return common.skip('Windows does not have "ps" utility');
2626
}
2727

28-
exec(`ps -p ${process.pid} -o args=`, function callback(error, stdout, stderr) {
28+
// To pass this test on alpine, since Busybox `ps` does not
29+
// support `-p` switch, use `ps -o` and `grep` instead.
30+
const cmd = common.isLinux ?
31+
`ps -o pid,args | grep '${process.pid} ${title}' | grep -v grep` :
32+
`ps -p ${process.pid} -o args=`;
33+
34+
exec(cmd, common.mustCall((error, stdout, stderr) => {
2935
assert.ifError(error);
3036
assert.strictEqual(stderr, '');
3137

@@ -34,5 +40,5 @@ exec(`ps -p ${process.pid} -o args=`, function callback(error, stdout, stderr) {
3440
title += ` (${path.basename(process.execPath)})`;
3541

3642
// omitting trailing whitespace and \n
37-
assert.strictEqual(stdout.replace(/\s+$/, ''), title);
38-
});
43+
assert.strictEqual(stdout.replace(/\s+$/, '').endsWith(title), true);
44+
}));

0 commit comments

Comments
 (0)