Skip to content

Commit

Permalink
test: fix parallel/test-setproctitle.js on alpine
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
  • Loading branch information
DavidCai1111 authored and evanlucas committed May 1, 2017
1 parent df4713b commit 0a1379e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/parallel/test-setproctitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const path = require('path');
// The title shouldn't be too long; libuv's uv_set_process_title() out of
// security considerations no longer overwrites envp, only argv, so the
// maximum title length is possibly quite short.
let title = 'testme';
let title = 'test';

assert.notStrictEqual(process.title, title);
process.title = title;
Expand All @@ -25,7 +25,13 @@ if (common.isWindows) {
return common.skip('Windows does not have "ps" utility');
}

exec(`ps -p ${process.pid} -o args=`, function callback(error, stdout, stderr) {
// To pass this test on alpine, since Busybox `ps` does not
// support `-p` switch, use `ps -o` and `grep` instead.
const cmd = common.isLinux ?
`ps -o pid,args | grep '${process.pid} ${title}' | grep -v grep` :
`ps -p ${process.pid} -o args=`;

exec(cmd, common.mustCall((error, stdout, stderr) => {
assert.ifError(error);
assert.strictEqual(stderr, '');

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

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

0 comments on commit 0a1379e

Please sign in to comment.