diff options
author | Ryan Timmons <ryan.timmons@mongodb.com> | 2019-09-10 18:03:51 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-10 18:03:51 +0000 |
commit | e7cc9e482621415c4c5361a98edb469a2024dcb7 (patch) | |
tree | 209ddc5a5508d8e203a4241535ba0c5c03088941 /jstests/noPassthrough | |
parent | 3e302760894b08b7a8d57f87106b152e165bc4dd (diff) | |
download | mongo-e7cc9e482621415c4c5361a98edb469a2024dcb7.tar.gz |
SERVER-43153 Expose pids of spawned processes in the shell
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/runningMongoChildProcessIds.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/jstests/noPassthrough/runningMongoChildProcessIds.js b/jstests/noPassthrough/runningMongoChildProcessIds.js new file mode 100644 index 00000000000..498e0556020 --- /dev/null +++ b/jstests/noPassthrough/runningMongoChildProcessIds.js @@ -0,0 +1,50 @@ +// Tests the _runningMongoChildProcessIds shell built-in. + +(function() { +'use strict'; + +/** + * @param {NumberLong[]} expected pids + */ +function assertRunningMongoChildProcessIds(expected) { + const expectedSorted = expected.sort(); + const children = MongoRunner.runningChildPids().sort(); + assert.eq(expectedSorted, children); +} + +// Empty before we start anything. +assertRunningMongoChildProcessIds([]); + +(function() { +// Start 1 mongod. +const mongod = MongoRunner.runMongod({}); +try { + // Call 3 times just for good-measure. + assertRunningMongoChildProcessIds([mongod.pid]); + assertRunningMongoChildProcessIds([mongod.pid]); + assertRunningMongoChildProcessIds([mongod.pid]); +} finally { + MongoRunner.stopMongod(mongod); +} +})(); + +(function() { +// Start 2 mongods. +const mongod1 = MongoRunner.runMongod({}); +const mongod2 = MongoRunner.runMongod({}); +try { + assertRunningMongoChildProcessIds([mongod1.pid, mongod2.pid]); + + // Stop mongod1 and only mongod2 should remain. + MongoRunner.stopMongod(mongod1); + assertRunningMongoChildProcessIds([mongod2.pid]); +} finally { + // It is safe to stop multiple times. + MongoRunner.stopMongos(mongod2); + MongoRunner.stopMongos(mongod1); +} +})(); + +// empty at the end +assertRunningMongoChildProcessIds([]); +})(); |