diff options
author | Randolph Tan <randolph@10gen.com> | 2015-04-20 15:36:09 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2015-05-11 10:09:05 -0400 |
commit | 9f0ceef0b37df2525cdebb172e6b05e2db8a2b20 (patch) | |
tree | 11fa779defcac750089916964aeee605d3330a17 /jstests | |
parent | b73ab5765fb75ae87ee5ad0f4afbc4fdfc2bc151 (diff) | |
download | mongo-9f0ceef0b37df2525cdebb172e6b05e2db8a2b20.tar.gz |
SERVER-18195 Read after optime (repl only)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/group_empty.js | 6 | ||||
-rw-r--r-- | jstests/core/read_after_optime.js | 22 | ||||
-rw-r--r-- | jstests/replsets/drop_oplog.js | 14 | ||||
-rw-r--r-- | jstests/replsets/read_after_optime_timeout.js | 105 | ||||
-rw-r--r-- | jstests/slow2/sharding_jscore_passthrough.js | 5 |
5 files changed, 140 insertions, 12 deletions
diff --git a/jstests/core/group_empty.js b/jstests/core/group_empty.js index 62a734ed0f8..c1772f88b22 100644 --- a/jstests/core/group_empty.js +++ b/jstests/core/group_empty.js @@ -5,4 +5,8 @@ t.drop(); res1 = db.runCommand({group: {$reduce: function(){}, ns: 'group_empty', cond: {}, key: {}, initial: {count: 0}}}); t.ensureIndex( { x : 1 } ); res2 = db.runCommand({group: {$reduce: function(){}, ns: 'group_empty', cond: {}, key: {}, initial: {count: 0}}}); -assert.eq( res1, res2 ); + +assert.docEq(res1.retval, res2.retval); +assert.eq(res1.keys, res2.keys); +assert.eq(res1.count, res2.count); + diff --git a/jstests/core/read_after_optime.js b/jstests/core/read_after_optime.js new file mode 100644 index 00000000000..d185b660887 --- /dev/null +++ b/jstests/core/read_after_optime.js @@ -0,0 +1,22 @@ +// Test that attempting to read after optime fails if replication is not enabled. + +(function() { +"use strict"; + +var currentTime = new Date(); + +var futureOpTime = new Timestamp((currentTime / 1000 + 3600), 0); + +var res = assert.commandFailed(db.runCommand({ + find: 'user', + filter: { x: 1 }, + after: { + opTime: { ts: futureOpTime, term: 0 } + } +})); + +assert.eq(123, res.code); // ErrorCodes::NotAReplicaSet +assert.eq(null, res.waitedMS); + +})(); + diff --git a/jstests/replsets/drop_oplog.js b/jstests/replsets/drop_oplog.js index 96c7582c4d9..90c920e1b27 100644 --- a/jstests/replsets/drop_oplog.js +++ b/jstests/replsets/drop_oplog.js @@ -10,16 +10,10 @@ var ml = master.getDB( 'local' ); var threw = false; - try { - ml.oplog.rs.drop(); - } - catch (err) { - assert.eq(err, - "Error: drop failed: { \"ok\" : 0, \"errmsg\" : " + - "\"can't drop live oplog while replicating\" }"); - threw = true; - } - assert(threw); + + var ret = assert.commandFailed(ml.runCommand({ drop: 'oplog.rs' })); + assert.eq('can\'t drop live oplog while replicating', ret.errmsg); + var dropOutput = ml.dropDatabase(); assert.eq(dropOutput.ok, 0); assert.eq(dropOutput.errmsg, "Cannot drop 'local' database while replication is active"); diff --git a/jstests/replsets/read_after_optime_timeout.js b/jstests/replsets/read_after_optime_timeout.js new file mode 100644 index 00000000000..0efee4fd8da --- /dev/null +++ b/jstests/replsets/read_after_optime_timeout.js @@ -0,0 +1,105 @@ +// Test read after opTime functionality with maxTimeMS. + +(function() { +"use strict"; + +var replTest = new ReplSetTest({ nodes: 2 }); +replTest.startSet(); + +var config = replTest.getReplSetConfig(); +// TODO: SERVER-18298 uncomment once implemented. +//config.protocolVersion = 1; +replTest.initiate(config); + +var runTest = function(testDB, primaryConn) { + primaryConn.getDB('test').user.insert({ x: 1 }, { writeConcern: { w: 2 }}); + + var localDB = primaryConn.getDB('local'); + + var oplogTS = localDB.oplog.rs.find().sort({ $natural: -1 }).limit(1).next().ts; + var twoSecTS = new Timestamp(oplogTS.getTime() + 2, 0); + + // Test timeout with maxTimeMS < after.opTime + var res = assert.commandFailed(testDB.runCommand({ + find: 'user', + filter: { x: 1 }, + after: { + opTime: { ts: twoSecTS, term: 0 }, + timeoutMS: 10 * 1000 + }, + maxTimeMS: 1000 + })); + + assert.eq(50, res.code); // ErrorCodes::ExceededTimeLimit + assert.gt(res.waitedMS, 500); + assert.lt(res.waitedMS, 2500); + + // Test timeout with after.opTime < maxTimeMS + res = assert.commandFailed(testDB.runCommand({ + find: 'user', + filter: { x: 1 }, + after: { + opTime: { ts: twoSecTS, term: 0 }, + timeoutMS: 1 * 1000 + }, + maxTimeMS: 10 * 1000 + })); + + assert.eq(122, res.code); // ErrorCodes::ReadAfterOptimeTimeout + assert.gt(res.waitedMS, 500); + assert.lt(res.waitedMS, 2500); + + // Test timeout with maxTimeMS, no after.timeout + res = assert.commandFailed(testDB.runCommand({ + find: 'user', + filter: { x: 1 }, + after: { + opTime: { ts: twoSecTS, term: 0 } + }, + maxTimeMS: 1 * 1000 + })); + + assert.eq(50, res.code); // ErrorCodes::ExceededTimeLimit + assert.gt(res.waitedMS, 500); + assert.lt(res.waitedMS, 2500); + + // Test timeout with after.opTime, no maxTimeMS + res = assert.commandFailed(testDB.runCommand({ + find: 'user', + filter: { x: 1 }, + after: { + opTime: { ts: twoSecTS, term: 0 }, + timeoutMS: 1 * 1000 + } + })); + + assert.eq(122, res.code); // ErrorCodes::ReadAfterOptimeTimeout + assert.gt(res.waitedMS, 500); + assert.lt(res.waitedMS, 2500); + + // Test read on future opTime that will eventually occur. + var insertFunc = startParallelShell( + "sleep(2100); db.user.insert({ y: 1 }, { writeConcern: { w: 2 }});", + primaryConn.port); + + res = assert.commandWorked(testDB.runCommand({ + find: 'user', + filter: { x: 1 }, + after: { + opTime: { ts: twoSecTS, term: 0 } + } + })); + + assert.eq(null, res.code); + assert.gt(res.waitedMS, 0); + + insertFunc(); +}; + +var primary = replTest.getPrimary(); +runTest(primary.getDB('test'), primary); +runTest(replTest.getSecondary().getDB('test'), primary); + +replTest.stopSet(); + +})(); diff --git a/jstests/slow2/sharding_jscore_passthrough.js b/jstests/slow2/sharding_jscore_passthrough.js index 44598d4ddc5..04bcd73235c 100644 --- a/jstests/slow2/sharding_jscore_passthrough.js +++ b/jstests/slow2/sharding_jscore_passthrough.js @@ -86,7 +86,10 @@ var db; 'auth1|' + 'auth2|' + 'dropdb_race|' + - 'unix_socket\\d*' + + 'unix_socket\\d*|' + + // TODO: SERVER-17284 remove once find cmd is + // implemented in mongos + 'read_after_optime' + ')\.js$'); // These are bugs (some might be fixed now): |