Browse files

SERVER-6878 Clean distinct3.js and make evalb.js more robust.

Conflicts:

	jstests/evalb.js
  • Loading branch information...
1 parent daf7aec commit 72cc3481b9e9ec791365b8ba6c183945e8093147 @astaple astaple committed with monkey101 Aug 28, 2012
Showing with 41 additions and 11 deletions.
  1. +9 −2 jstests/distinct3.js
  2. +32 −9 jstests/evalb.js
View
11 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;
View
41 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;
+}

0 comments on commit 72cc348

Please sign in to comment.