Skip to content

Commit

Permalink
findMongoPids: use pgrep where available
Browse files Browse the repository at this point in the history
ps corrupts some non-ASCII characters on OS X.  pgrep doesn't, but isn't
available everywhere.

Fixes #3999.
  • Loading branch information
glasser committed Mar 31, 2015
1 parent 65be782 commit f14464b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tools/run-mongo.js
Expand Up @@ -124,8 +124,26 @@ if (process.platform === 'win32') {
var fut = new Future;

// 'ps ax' should be standard across all MacOS and Linux.
// However, ps on OS X corrupts some non-ASCII characters in arguments,
// such as т (CYRILLIC SMALL LETTER TE), leading to this function
// failing to properly match pathnames with those characters. #3999
//
// pgrep appears to do a better job (and has output that is roughly
// similar; it lacks a few fields that we don't care about). Plus,
// it can do some of the grepping for us.
//
// However, 'pgrep' only started shipping with OS X 10.8 (and may be less
// common on Linux too), so we check to see if it exists and fall back to
// 'ps' if we can't find it.
child_process.exec(
'ps ax',
'if type pgrep >/dev/null 2>&1; then ' +
// -lf means to display and match against full argument lists.
// pgrep exits 1 if no processes match the argument; we're OK
// considering this as a success, but we don't want other errors
// to be ignored. Note that this is sh not bash, so we can't use
// [[.
'pgrep -lf mongod; test "$?" -eq 0 -o "$?" -eq 1;' +
'else ps ax; fi',
// we don't want this to randomly fail just because you're running lots of
// processes. 10MB should be more than ps ax will ever spit out; the default
// is 200K, which at least one person hit (#2158).
Expand Down
35 changes: 35 additions & 0 deletions tools/tests/mongo.js
Expand Up @@ -19,3 +19,38 @@ selftest.define("mongo failover", ["slow"], function () {
run.expectEnd();
run.expectExit(0);
});

var testMeteorMongo = function (appDir) {
var s = new Sandbox();
s.createApp(appDir, 'standard-app');
s.cd(appDir);

var run = s.run();
run.waitSecs(15);
run.match(appDir);
run.match('proxy');
run.match('Started MongoDB');

var mongoRun = s.run('mongo');
mongoRun.match('MongoDB shell');
mongoRun.match('connecting to: 127.0.0.1');
// Note: when mongo shell's input is not a tty, there is no prompt.
mongoRun.write('db.version()\n');
mongoRun.match(/2\.6\.\d+/);
mongoRun.stop();
};

selftest.define("meteor mongo", function () {
testMeteorMongo('asdfzasdf');
});

// Regression test for #3999. Note the Cyrillic character in the pathname.
//
// XXX This test fails on Windows for two different reasons:
// - With the Unicode directory name, `meteor run` fails to start mongod
// - If you change appDir to not have the Unicode character, the reads
// from the mongo shell process seem to be randomly corrupted
// https://github.com/meteor/windows-preview/issues/145
selftest.define("meteor mongo in unicode dir", function () {
testMeteorMongo('asdf\u0442asdf');
});

0 comments on commit f14464b

Please sign in to comment.