summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2012-08-28 23:14:12 -0700
committerDan Pasette <dan@10gen.com>2012-09-12 15:58:51 -0400
commit72cc3481b9e9ec791365b8ba6c183945e8093147 (patch)
tree9608ad8def8aaaa0570a4461279e13b5dc72ab3b
parentdaf7aec921bf7f5b8be46bb0bffe2c51984692ff (diff)
downloadmongo-72cc3481b9e9ec791365b8ba6c183945e8093147.tar.gz
SERVER-6878 Clean distinct3.js and make evalb.js more robust.
Conflicts: jstests/evalb.js
-rw-r--r--jstests/distinct3.js11
-rw-r--r--jstests/evalb.js41
2 files changed, 41 insertions, 11 deletions
diff --git a/jstests/distinct3.js b/jstests/distinct3.js
index f945ec9d7e8..22117824dd7 100644
--- a/jstests/distinct3.js
+++ b/jstests/distinct3.js
@@ -16,8 +16,15 @@ for( i = 0; i < 1000; ++i ) {
}
db.getLastError();
-// The idea here is to try and remove the last match for the {a:1} index scan while distinct is yielding.
-p = startParallelShell( 'for( i = 0; i < 2500; ++i ) { db.jstests_distinct3.remove({a:49}); for( j = 0; j < 20; ++j ) { db.jstests_distinct3.save({a:49,c:49,d:j}) } }' );
+// Attempt to remove the last match for the {a:1} index scan while distinct is yielding.
+p = startParallelShell( 'for( i = 0; i < 2500; ++i ) { ' +
+ ' db.jstests_distinct3.remove( { a:49 } ); ' +
+ ' for( j = 0; j < 20; ++j ) { ' +
+ ' db.jstests_distinct3.save( { a:49, c:49, d:j } ); ' +
+ ' } ' +
+ '} ' +
+ '// Wait for the above writes to complete. ' +
+ 'db.getLastError(); ' );
for( i = 0; i < 100; ++i ) {
count = t.distinct( 'c', {$or:[{a:{$gte:0},d:0},{b:{$gte:0}}]} ).length;
diff --git a/jstests/evalb.js b/jstests/evalb.js
index ea803317083..aa56e972384 100644
--- a/jstests/evalb.js
+++ b/jstests/evalb.js
@@ -1,17 +1,40 @@
+// Check the return value of a db.eval function running a database query, and ensure the function's
+// contents are logged in the profile log.
-t = db.evalb;
-t.drop();
+// Use a reserved database name to avoid a conflict in the parallel test suite.
+var stddb = db;
+var db = db.getSisterDB( 'evalb' );
-t.save( { x : 3 } );
+function profileCursor() {
+ return db.system.profile.find( { user:username } );
+}
-assert.eq( 3, db.eval( function(){ return db.evalb.findOne().x; } ) , "A" );
+function lastOp() {
+ return profileCursor().sort( { $natural:-1 } ).next();
+}
-db.setProfilingLevel( 2 );
+try {
-assert.eq( 3, db.eval( function(){ return db.evalb.findOne().x; } ) , "B" );
+ username = 'jstests_evalb_user';
+ db.addUser( username, 'password', false, 1 );
+ db.auth( username, 'password' );
-o = db.system.profile.find().sort( { $natural : -1 } ).limit(1).next();
-assert( tojson(o).indexOf( "findOne().x" ) > 0 , "C : " + tojson( o ) )
+ t = db.evalb;
+ t.drop();
-db.setProfilingLevel( 0 );
+ t.save( { x:3 } );
+ assert.eq( 3, db.eval( function() { return db.evalb.findOne().x; } ), 'A' );
+
+ db.setProfilingLevel( 2 );
+
+ assert.eq( 3, db.eval( function() { return db.evalb.findOne().x; } ), 'B' );
+
+ o = lastOp();
+ assert( tojson( o ).indexOf( 'findOne().x' ) > 0, 'C : ' + tojson( o ) );
+}
+finally {
+
+ db.setProfilingLevel(0);
+ db = stddb;
+}