diff options
author | Daniel Gottlieb <daniel.gottlieb@10gen.com> | 2016-11-10 10:36:35 -0500 |
---|---|---|
committer | Daniel Gottlieb <daniel.gottlieb@10gen.com> | 2016-12-09 09:10:13 -0500 |
commit | 03f702f59d7d09a76f3c16944ae1ec48c4b25046 (patch) | |
tree | 395471bd1dd971653e03a2abd0455b24c304177a | |
parent | c586934f7212f6a9a2087cbaf9a8fcd7d7ce9abf (diff) | |
download | mongo-03f702f59d7d09a76f3c16944ae1ec48c4b25046.tar.gz |
SERVER-26693: Wait on shell process before exiting scripts
(cherry picked from commit 5ab5efc9b17be8a4ecebf845c9e07c0f15a67e0e)
-rw-r--r-- | jstests/noPassthrough/indexbg1.js | 18 | ||||
-rw-r--r-- | jstests/noPassthrough/indexbg2.js | 20 |
2 files changed, 28 insertions, 10 deletions
diff --git a/jstests/noPassthrough/indexbg1.js b/jstests/noPassthrough/indexbg1.js index 62e3617fe9f..00670f3f2db 100644 --- a/jstests/noPassthrough/indexbg1.js +++ b/jstests/noPassthrough/indexbg1.js @@ -14,13 +14,15 @@ var resetParallel = function() { parallel().drop(); }; +// Return the PID to call `waitpid` on for clean shutdown. var doParallel = function(work) { resetParallel(); print("doParallel: " + work); - startMongoProgramNoConnect("mongo", - "--eval", - work + "; db." + baseName + "_parallelStatus.save( {done:1} );", - db.getMongo().host); + return startMongoProgramNoConnect( + "mongo", + "--eval", + work + "; db." + baseName + "_parallelStatus.save( {done:1} );", + db.getMongo().host); }; var doneParallel = function() { @@ -34,6 +36,7 @@ var waitParallel = function() { }; var size = 400 * 1000; +var bgIndexBuildPid; while (1) { // if indexing finishes before we can run checks, try indexing w/ more data print("size: " + size); @@ -48,7 +51,7 @@ while (1) { // if indexing finishes before we can run checks, try indexing w/ m assert.writeOK(bulk.execute()); assert.eq(size, t.count()); - doParallel(fullName + ".ensureIndex( {i:1}, {background:true} )"); + bgIndexBuildPid = doParallel(fullName + ".ensureIndex( {i:1}, {background:true} )"); try { // wait for indexing to start print("wait for indexing to start"); @@ -98,12 +101,17 @@ while (1) { // if indexing finishes before we can run checks, try indexing w/ m break; } print("indexing finished too soon, retrying..."); + // Although the index build finished, ensure the shell has exited. + waitProgram(bgIndexBuildPid); size *= 2; assert(size < 200000000, "unable to run checks in parallel with index creation"); } print("our tests done, waiting for parallel to finish"); waitParallel(); +// Ensure the shell has exited cleanly. Otherwise the test harness may send a SIGTERM which can lead +// to a false test failure. +waitProgram(bgIndexBuildPid); print("finished"); assert.eq(1, t.count({i: -10})); diff --git a/jstests/noPassthrough/indexbg2.js b/jstests/noPassthrough/indexbg2.js index 5fcd975a98f..e9ac45c8b78 100644 --- a/jstests/noPassthrough/indexbg2.js +++ b/jstests/noPassthrough/indexbg2.js @@ -14,12 +14,14 @@ var resetParallel = function() { parallel().drop(); }; +// Return the PID to call `waitpid` on for clean shutdown. var doParallel = function(work) { resetParallel(); - startMongoProgramNoConnect("mongo", - "--eval", - work + "; db." + baseName + "_parallelStatus.save( {done:1} );", - db.getMongo().host); + return startMongoProgramNoConnect( + "mongo", + "--eval", + work + "; db." + baseName + "_parallelStatus.save( {done:1} );", + db.getMongo().host); }; var doneParallel = function() { @@ -35,6 +37,7 @@ var waitParallel = function() { var doTest = function() { "use strict"; var size = 10000; + var bgIndexBuildPid; while (1) { // if indexing finishes before we can run checks, try indexing w/ more data print("size: " + size); var fullName = "db." + baseName; @@ -46,7 +49,8 @@ var doTest = function() { } assert.eq(size, t.count()); - doParallel(fullName + ".ensureIndex( {i:1}, {background:true, unique:true} )"); + bgIndexBuildPid = + doParallel(fullName + ".ensureIndex( {i:1}, {background:true, unique:true} )"); try { // wait for indexing to start assert.soon(function() { @@ -59,13 +63,19 @@ var doTest = function() { // wait for parallel status to update to reflect indexing status sleep(1000); if (!doneParallel()) { + waitProgram(bgIndexBuildPid); throw e; } } if (!doneParallel()) { + // Ensure the shell has exited cleanly. Otherwise the test harness may send a SIGTERM + // which can lead to a false test failure. + waitProgram(bgIndexBuildPid); break; } print("indexing finished too soon, retrying..."); + // Although the index build finished, ensure the shell has exited. + waitProgram(bgIndexBuildPid); size *= 2; assert(size < 5000000, "unable to run checks in parallel with index creation"); } |