Running the following in the shell:
results in the shell terminating immediately with
and no other information. I think it ends up sending a SIGTERM to the running shell process. Instead we should validate that the passed port number is an integer.
Calls to _stopMongoProgram should be through the corresponding shell wrappers like MongoRunner.stopMongod. However, this did surface for me in real life when accidentally passing a DB object instead of a Mongo object, ala:
MongoRunner.stopMongod validates that the passed object has the "port" and "pid" properties, But since the db object says it has any property (for collections) it gets through to the call of _stopMongoProgram and passes NaN as the PID.
This could be fixed just to validate that the passed port is an integer.
Note that stopMongoProgramByPid doesn't have this issue. It gives an invariant failure indicating the PID is invalid:
Another note. When testing these functions, tread carefully. Don't run stopMongoProgramByPid on a floating point that rounds down to 1 as you'll likely need to restart your computer... speaking from experience.