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.

Backport-PR-URL: #13072
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 MylesBorins committed Jul 11, 2017
1 parent 7bda962 commit c902265
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,13 +14,19 @@ 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;
assert.strictEqual(process.title, title);

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 @@ -29,5 +35,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 c902265

Please sign in to comment.