Navigation Menu

Skip to content

Commit

Permalink
SERVER-6878 Clean distinct3.js and make evalb.js more robust.
Browse files Browse the repository at this point in the history
Conflicts:

	jstests/evalb.js
  • Loading branch information
astaple authored and monkey101 committed Sep 12, 2012
1 parent daf7aec commit 72cc348
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
11 changes: 9 additions & 2 deletions jstests/distinct3.js
Expand Up @@ -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;
Expand Down
41 changes: 32 additions & 9 deletions 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.