summaryrefslogtreecommitdiff
path: root/jstests/mr_drop.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/mr_drop.js')
-rw-r--r--jstests/mr_drop.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/jstests/mr_drop.js b/jstests/mr_drop.js
new file mode 100644
index 00000000000..8c4f9f8846f
--- /dev/null
+++ b/jstests/mr_drop.js
@@ -0,0 +1,38 @@
+// Drop a collection while a map/reduce job is running against it. SERVER-6757
+
+t = db.jstests_mr_drop;
+t.drop();
+
+Random.setRandomSeed();
+
+// Set sleep times for different stages of the map/reduce job. The collection drop will occur
+// during different stages of map/reduce depending on these sleep values.
+mapSleep = Random.randInt( 4 );
+reduceSleep = Random.randInt( 4 );
+finalizeSleep = Random.randInt( 4 );
+
+// Insert some documents.
+for( i = 0; i < 10000; ++i ) {
+ t.save( { key:parseInt( i / 2 ),
+ mapSleep:mapSleep,
+ reduceSleep:reduceSleep,
+ finalizeSleep:finalizeSleep } );
+}
+db.getLastError();
+
+// Schedule a collection drop two seconds in the future.
+s = startParallelShell( "sleep( 2000 ); db.jstests_mr_drop.drop();" );
+
+// Run the map/reduce job. Check for command failure internally. The job succeeds even if the
+// source collection is dropped in progress.
+t.mapReduce( function() { sleep( this.mapSleep ); emit( this.key, this ); },
+ function( key, vals ) { sleep( vals[ 0 ].reduceSleep ); return vals[ 0 ]; },
+ { finalize:function( key, value ) { sleep( value.finalizeSleep ); return value; },
+ out:'jstests_mr_drop_out' }
+ );
+
+// Wait for the parallel shell to finish.
+s();
+
+// Ensure the server is still alive. Under SERVER-6757 the server can crash.
+assert( !db.getLastError() );