Skip to content

Commit

Permalink
Revert "SERVER-13741 Migrate remaining tests to use write commands"
Browse files Browse the repository at this point in the history
This reverts commit 87dc3ae.
  • Loading branch information
dstorch committed May 6, 2014
1 parent 3061ab5 commit 7238072
Show file tree
Hide file tree
Showing 118 changed files with 1,359 additions and 1,196 deletions.
11 changes: 7 additions & 4 deletions buildscripts/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,14 @@ def skipTest(path):

return False

legacyWriteRE = re.compile(r"jstests[/\\]multiVersion")
forceCommandsForDirs = ["aggregation", "auth", "core", "parallel", "replsets", "sharding"]
# look for jstests and one of the above suites separated by either posix or windows slashes
forceCommandsRE = re.compile(r"jstests[/\\](%s)" % ('|'.join(forceCommandsForDirs)))
def setShellWriteModeForTest(path, argv):
swm = shell_write_mode
if legacyWriteRE.search(path):
swm = "legacy"
if swm == "legacy": # change when the default changes to "commands"
if use_write_commands or forceCommandsRE.search(path):
swm = "commands"
argv += ["--writeMode", swm]

def runTest(test, result):
Expand Down Expand Up @@ -1205,7 +1208,7 @@ def main():
parser.add_option('--use-write-commands', dest='use_write_commands', default=False,
action='store_true',
help='Deprecated(use --shell-write-mode): Sets the shell to use write commands by default')
parser.add_option('--shell-write-mode', dest='shell_write_mode', default="commands",
parser.add_option('--shell-write-mode', dest='shell_write_mode', default="legacy",
help='Sets the shell to use a specific write mode: commands/compatibility/legacy (default:legacy)')

global tests
Expand Down
1 change: 1 addition & 0 deletions jstests/auth/lib/commands_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,7 @@ var authCommandsLib = {
command: {renameCollection: firstDbName + ".x", to: secondDbName + ".y"},
setup: function (db) {
db.getSisterDB(firstDbName).x.save( {} );
db.getSisterDB(firstDbName).getLastError();
db.getSisterDB(adminDbName).runCommand({movePrimary: firstDbName, to: shard0name});
db.getSisterDB(adminDbName).runCommand({movePrimary: secondDbName, to: shard0name});
},
Expand Down
10 changes: 5 additions & 5 deletions jstests/disk/diskfull.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ if ( doIt ) {
m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1", '--nojournal' );
d = m.getDB( "diskfulltest" );
c = d.getCollection( "diskfulltest" );
assert.writeError(c.insert( { a: 6 } ));

c.save( { a: 6 } );
assert(d.getLastError().length );
printjson( d.getLastErrorObj() );
assert.soon(
function() { c.save( { a : 6 } );
return rawMongoProgramOutput().match( /file allocation failure/ );
},
"didn't see 'file allocation failure'" );
res = assert.writeError(c.insert({ a: 6 }));
var errmsg = res.getWriteError().errmsg;
assert.eq(errmsg, "Can't take a write lock while out of disk space"); // every following fail
c.save( { a: 6 } );
assert.eq(d.getLastError(), "Can't take a write lock while out of disk space"); // every following fail


sleep( 3000 );
Expand Down
3 changes: 2 additions & 1 deletion jstests/disk/killall.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var mongod = startMongod( "--port", port, "--dbpath", dbpath, "--nohttpinterface
var db = mongod.getDB( "test" );
var collection = db.getCollection( baseName );

assert.writeOK(collection.insert({}));
collection.save( {} );
assert( ! db.getLastError() );

s1 = startParallelShell( "db." + baseName + ".count( { $where: function() { while( 1 ) { ; } } } )", port );
// HACK(schwerin): startParallelShell's return value should allow you to block until the command has
Expand Down
16 changes: 8 additions & 8 deletions jstests/disk/preallocate_directoryperdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ function checkDb2DirAbsent() {
var m = startMongod( "--smallfiles", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
db2 = m.getDB( baseName2 );
var bulk = db[ baseName ].initializeUnorderedBulkOp();
var bulk2 = db2[ baseName2 ].initializeUnorderedBulkOp();
var big = new Array( 5000 ).toString();
c = db[ baseName ];
c2 = db2[ baseName2 ];
big = new Array( 5000 ).toString();
for( var i = 0; i < 3000; ++i ) {
bulk.insert({ b:big });
bulk2.insert({ b:big });
c.save( { b:big } );
c2.save( { b:big } );
db.getLastError();
}
assert.writeOK(bulk.execute());
assert.writeOK(bulk2.execute());

// Due to our write pattern, we expect db2's .3 file to be queued up in the file
// allocator behind db's .3 file at the time db2 is dropped. This will
Expand All @@ -44,7 +43,8 @@ db.dropDatabase();
// Try writing a new database, to ensure file allocator is still working.
db3 = m.getDB( baseName3 );
c3 = db[ baseName3 ];
assert.writeOK(c3.insert( {} ));
c3.save( {} );
assert( !db3.getLastError() );
assert.eq( 1, c3.count() );

checkDb2DirAbsent();
10 changes: 5 additions & 5 deletions jstests/disk/quota.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ db = m.getDB( baseName );
big = new Array( 10000 ).toString();

// Insert documents until quota is exhausted.
var coll = db[ baseName ];
var res = coll.insert({ b: big });
while( !res.hasWriteError() ) {
res = coll.insert({ b: big });
while( !db.getLastError() ) {
db[ baseName ].save( {b:big} );
}
printjson( db.getLastError() );

dotTwoDataFile = baseName + ".2";
files = listFiles( dbpath );
Expand All @@ -28,7 +27,8 @@ dotTwoDataFile = "local" + ".2";
// Check that quota does not apply to local db, and a .2 file can be created.
l = m.getDB( "local" )[ baseName ];
for( i = 0; i < 10000; ++i ) {
assert.writeOK(l.insert({ b: big }));
l.save( {b:big} );
assert( !db.getLastError() );
dotTwoFound = false;
if ( i % 100 != 0 ) {
continue;
Expand Down
16 changes: 8 additions & 8 deletions jstests/disk/quota2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ db = m.getDB( baseName );
big = new Array( 10000 ).toString();

// Insert documents until quota is exhausted.
var coll = db[ baseName ];
var res = coll.insert({ b: big });
while( !res.hasWriteError() ) {
res = coll.insert({ b: big });
while( !db.getLastError() ) {
db[ baseName ].save( {b:big} );
}

db.resetError();

// Trigger allocation of an additional file for a 'special' namespace.
for( n = 0; !db.getLastError(); ++n ) {
db.createCollection( '' + n );
Expand All @@ -27,10 +27,10 @@ for( n = 0; !db.getLastError(); ++n ) {
// Check that new docs are saved in the .0 file.
for( i = 0; i < n; ++i ) {
c = db[ ''+i ];
res = c.insert({ b: big });
if( !res.hasWriteError() ) {
assert.eq( 0, c.find()._addSpecial( "$showDiskLoc", true )[ 0 ].$diskLoc.file );
c.save( {b:big} );
if( !db.getLastError() ) {
assert.eq( 0, c.find()._addSpecial( "$showDiskLoc", true )[ 0 ].$diskLoc.file );
}
}

}
}
6 changes: 4 additions & 2 deletions jstests/dur/a_quick.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ tst.log("start mongod without dur");
var conn = startMongodEmpty("--port", 30000, "--dbpath", path1, "--nodur");
tst.log("without dur work");
var d = conn.getDB("test");
assert.writeOK(d.foo.insert({ _id: 123 }));
d.foo.insert({ _id:123 });
d.getLastError();
tst.log("stop without dur");
stopMongod(30000);

Expand All @@ -71,7 +72,8 @@ tst.log("start mongod with dur");
conn = startMongodEmpty("--port", 30001, "--dbpath", path2, "--dur", "--durOptions", 8);
tst.log("with dur work");
d = conn.getDB("test");
assert.writeOK(d.foo.insert({ _id: 123 }));
d.foo.insert({ _id: 123 });
d.getLastError(); // wait

// we could actually do getlasterror fsync:1 now, but maybe this is agood
// as it will assure that commits happen on a timely basis. a bunch of the other dur/*js
Expand Down
39 changes: 21 additions & 18 deletions jstests/dur/closeall.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@ function f(variant, quickCommits, paranoid) {
print("closeall.js run test");

print("wait for initial sync to finish") // SERVER-4852
assert.writeOK(db1.foo.insert({}, { writeConcern: { w: 2 }}));
assert.writeOK(db1.foo.remove({}, { writeConcern: { w: 2 }}));
db1.foo.insert({});
err = db1.getLastErrorObj(2);
printjson(err)
assert.isnull(err.err);
db1.foo.remove({});
err = db1.getLastErrorObj(2);
printjson(err)
assert.isnull(err.err);
print("initial sync done")

var writeOps = startParallelShell('var coll = db.getSiblingDB("closealltest").foo; \
var bulk = coll.initializeUnorderedBulkOp(); \
for( var i = 0; i < ' + N + '; i++ ) { \
bulk.insert({ x: 1 }); \
if ( i % 7 == 0 ) \
bulk.insert({ x: 99, y: 2 }); \
if ( i % 49 == 0 ) \
bulk.find({ x: 99 }).update( \
{ a: 1, b: 2, c: 3, d: 4 }); \
if( i == 800 ) \
coll.ensureIndex({ x: 1 }); \
}', 30001);

for( var i = 0; i < N; i++ ) {
for( var i = 0; i < N; i++ ) {
db1.foo.insert({x:1}); // this does wait for a return code so we will get some parallelism
if( i % 7 == 0 )
db1.foo.insert({x:99, y:2});
if( i % 49 == 0 )
db1.foo.update({ x: 99 }, { a: 1, b: 2, c: 3, d: 4 });
if (i % 100 == 0)
db1.foo.find();
if( i == 800 )
db1.foo.ensureIndex({ x: 1 });
var res = null;
try {
if( variant == 1 )
Expand All @@ -59,6 +61,7 @@ function f(variant, quickCommits, paranoid) {
res = db2.adminCommand("closeAllDatabases");
}
catch (e) {
sleep(5000); // sleeping a little makes console output order prettier
print("\n\n\nFAIL closeall.js closeAllDatabases command invocation threw an exception. i:" + i);
try {
print("getlasterror:");
Expand All @@ -71,6 +74,8 @@ function f(variant, quickCommits, paranoid) {
print("got another exception : " + e);
}
print("\n\n\n");
// sleep a little to capture possible mongod output?
sleep(2000);
throw e;
}
assert( res.ok, "closeAllDatabases res.ok=false");
Expand All @@ -82,8 +87,6 @@ function f(variant, quickCommits, paranoid) {
print("closeall.js shutting down servers");
stopMongod(30002);
stopMongod(30001);

writeOps();
}

// Skip this test on 32-bit Windows (unfixable failures in MapViewOfFileEx)
Expand Down
11 changes: 7 additions & 4 deletions jstests/dur/diskfull.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ function work() {
log("work");
try {
var d = conn.getDB("test");
var big = new Array( 5000 ).toString();
var bulk = d.foo.initializeUnorderedBulkOp();

big = new Array( 5000 ).toString();
for( i = 0; i < 10000; ++i ) {
bulk.insert({ _id: i, b: big });
d.foo.insert( { _id:i, b:big } );
}
assert.writeOK(bulk.execute());

gle = d.getLastError();
if ( gle )
throw gle;
} catch ( e ) {
print( e );
raise( e );
Expand Down
4 changes: 3 additions & 1 deletion jstests/dur/dropdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ function work() {

d.dropDatabase();

d.foo.insert({ _id: 100 });

// assure writes applied in case we kill -9 on return from this function
assert.writeOK(d.foo.insert({ _id: 100 }, { writeConcern: { fsync: 1 }}));
assert(d.runCommand({ getlasterror: 1, fsync: 1 }).ok, "getlasterror not ok");
}

function verify() {
Expand Down
6 changes: 6 additions & 0 deletions jstests/dur/dur1.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function work() {
// try building an index. however, be careful as object id's in system.indexes would vary, so we do it manually:
d.system.indexes.insert({ _id: 99, ns: "test.a", key: { x: 1 }, name: "x_1", v: 0 });

// d.a.update({ _id: 4 }, { $inc: { x: 1} });
// d.a.reIndex();

// assure writes applied in case we kill -9 on return from this function
d.getLastError();

log("endwork");
return d;
}
Expand Down
7 changes: 7 additions & 0 deletions jstests/dur/dur1_tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function work() {

// try building an index. however, be careful as object id's in system.indexes would vary, so we do it manually:
d.system.indexes.insert({ _id: 99, ns: "test.a", key: { x: 1 }, name: "x_1", v: 0 });

// d.a.update({ _id: 4 }, { $inc: { x: 1} });
// d.a.reIndex();

// assure writes applied in case we kill -9 on return from this function
d.getLastError();

log("endwork");
return d;
}
Expand Down
4 changes: 2 additions & 2 deletions jstests/dur/indexbg2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ for( var i = 1000; i < 2000; ++i ) {
t.insert( {_id:i,a:'abcd',b:'bcde',x:'four score and seven years ago'} );
t.remove( {_id:i} );
}
assert.writeOK(t.insert({ _id: 2000, a: 'abcd', b: 'bcde', x: 'four score and seven years ago' }));

t.insert( {_id:2000,a:'abcd',b:'bcde',x:'four score and seven years ago'} );
assert( !t.getDB().getLastError() );
6 changes: 6 additions & 0 deletions jstests/dur/manyRestart.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ function work() {

// try building an index. however, be careful as object id's in system.indexes would vary, so we do it manually:
d.system.indexes.insert({ _id: 99, ns: "test.a", key: { x: 1 }, name: "x_1", v: 0 });

// d.a.update({ _id: 4 }, { $inc: { x: 1} });
// d.a.reIndex();

// assure writes applied in case we kill -9 on return from this function
d.getLastError();
log("endwork");
return d;
}
Expand Down
7 changes: 7 additions & 0 deletions jstests/dur/md5.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ function work() {

// try building an index. however, be careful as object id's in system.indexes would vary, so we do it manually:
d.system.indexes.insert({ _id: 99, ns: "test.a", key: { x: 1 }, name: "x_1", v: 0 });

// d.a.update({ _id: 4 }, { $inc: { x: 1} });
// d.a.reIndex();

// assure writes applied in case we kill -9 on return from this function
d.getLastError();

log("endwork");
}

Expand Down
3 changes: 3 additions & 0 deletions jstests/dur/oplog.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ function work() {
d.foo.insert({ _id: 6, q: "aaaaa", b: big, z: 3 });
d.foo.update({ _id: 5 }, { $set: { z: 99} });

// assure writes applied in case we kill -9 on return from this function
d.getLastError();

log("endwork");

verify();
Expand Down
Loading

0 comments on commit 7238072

Please sign in to comment.