diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2016-03-09 12:17:50 -0500 |
---|---|---|
committer | Jonathan Abrahams <jonathan@mongodb.com> | 2016-03-09 12:18:14 -0500 |
commit | 4ae691e8edc87d0e3cfb633bb91c328426be007b (patch) | |
tree | 52079a593f54382ca13a2e741633eab1b6271893 /jstests/replsets/read_after_optime.js | |
parent | a025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff) | |
download | mongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz |
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/replsets/read_after_optime.js')
-rw-r--r-- | jstests/replsets/read_after_optime.js | 172 |
1 files changed, 84 insertions, 88 deletions
diff --git a/jstests/replsets/read_after_optime.js b/jstests/replsets/read_after_optime.js index cff0896344e..30cf7782679 100644 --- a/jstests/replsets/read_after_optime.js +++ b/jstests/replsets/read_after_optime.js @@ -1,108 +1,104 @@ // Test read after opTime functionality with maxTimeMS. (function() { -"use strict"; + "use strict"; -var replTest = new ReplSetTest({ nodes: 2 }); -replTest.startSet(); -replTest.initiate(); -var config = replTest.getReplSetConfigFromNode(); + var replTest = new ReplSetTest({nodes: 2}); + replTest.startSet(); + replTest.initiate(); + var config = replTest.getReplSetConfigFromNode(); -var runTest = function(testDB, primaryConn) { - primaryConn.getDB('test').user.insert({ x: 1 }, { writeConcern: { w: 2 }}); + var runTest = function(testDB, primaryConn) { + primaryConn.getDB('test').user.insert({x: 1}, {writeConcern: {w: 2}}); - var localDB = primaryConn.getDB('local'); + var localDB = primaryConn.getDB('local'); - var oplogTS = localDB.oplog.rs.find().sort({ $natural: -1 }).limit(1).next(); - var twoSecTS = new Timestamp(oplogTS.ts.getTime() + 2, 0); + var oplogTS = localDB.oplog.rs.find().sort({$natural: -1}).limit(1).next(); + var twoSecTS = new Timestamp(oplogTS.ts.getTime() + 2, 0); - var term = -1; - if (config.protocolVersion === 1) { - term = oplogTS.t; - } + var term = -1; + if (config.protocolVersion === 1) { + term = oplogTS.t; + } - // Test timeout with maxTimeMS - var runTimeoutTest = function() { - var timeoutResult = assert.commandFailedWithCode( - testDB.runCommand({ + // Test timeout with maxTimeMS + var runTimeoutTest = function() { + var timeoutResult = assert.commandFailedWithCode(testDB.runCommand({ find: 'user', - filter: { x: 1 }, - readConcern: { - afterOpTime: { ts: twoSecTS, t: term } - }, + filter: {x: 1}, + readConcern: {afterOpTime: {ts: twoSecTS, t: term}}, maxTimeMS: 5000, }), - ErrorCodes.ExceededTimeLimit - ); - assert.gt(timeoutResult.waitedMS, 500); - }; - - var countLogMessages = function(msg) { - var total = 0; - var logMessages = assert.commandWorked(testDB.adminCommand({getLog: 'global'})).log; - for (var i = 0; i < logMessages.length; i++) { - if (logMessages[i].indexOf(msg) != -1) { - total++; + ErrorCodes.ExceededTimeLimit); + assert.gt(timeoutResult.waitedMS, 500); + }; + + var countLogMessages = function(msg) { + var total = 0; + var logMessages = assert.commandWorked(testDB.adminCommand({getLog: 'global'})).log; + for (var i = 0; i < logMessages.length; i++) { + if (logMessages[i].indexOf(msg) != -1) { + total++; + } } - } - return total; - }; - - var checkLog = function(msg, expectedCount) { - var count; - assert.soon(function() { - count = countLogMessages(msg); - return expectedCount == count; + return total; + }; + + var checkLog = function(msg, expectedCount) { + var count; + assert.soon( + function() { + count = countLogMessages(msg); + return expectedCount == count; + }, + 'Expected ' + expectedCount + ', but instead saw ' + count + + ' log entries containing the following message: ' + msg, + 60000, + 300); + }; + + // Run the time out test 3 times with replication debug log level increased to 2 + // for first and last run. The time out message should be logged twice. + testDB.setLogLevel(2, 'command'); + runTimeoutTest(); + testDB.setLogLevel(0, 'command'); + + var msg = 'Command on database ' + testDB.getName() + + ' timed out waiting for read concern to be satisfied. Command:'; + checkLog(msg, 1); + + // Read concern timed out message should not be logged. + runTimeoutTest(); + + testDB.setLogLevel(2, 'command'); + runTimeoutTest(); + testDB.setLogLevel(0, 'command'); + + checkLog(msg, 2); + + // Test read on future afterOpTime that will eventually occur. + var insertFunc = startParallelShell( + "sleep(2100); db.user.insert({ y: 1 }, { writeConcern: { w: 2 }});", primaryConn.port); + + var res = assert.commandWorked(testDB.runCommand({ + find: 'user', + filter: {x: 1}, + readConcern: { + afterOpTime: {ts: twoSecTS, t: term}, }, - 'Expected ' + expectedCount + ', but instead saw ' + count + - ' log entries containing the following message: ' + msg, - 60000, - 300); - }; + maxTimeMS: 10 * 1000, + })); - // Run the time out test 3 times with replication debug log level increased to 2 - // for first and last run. The time out message should be logged twice. - testDB.setLogLevel(2, 'command'); - runTimeoutTest(); - testDB.setLogLevel(0, 'command'); + assert.eq(null, res.code); + assert.gt(res.waitedMS, 0); - var msg = 'Command on database ' + testDB.getName() + - ' timed out waiting for read concern to be satisfied. Command:'; - checkLog(msg, 1); - - // Read concern timed out message should not be logged. - runTimeoutTest(); - - testDB.setLogLevel(2, 'command'); - runTimeoutTest(); - testDB.setLogLevel(0, 'command'); - - checkLog(msg, 2); - - // Test read on future afterOpTime that will eventually occur. - var insertFunc = startParallelShell( - "sleep(2100); db.user.insert({ y: 1 }, { writeConcern: { w: 2 }});", - primaryConn.port); - - var res = assert.commandWorked(testDB.runCommand({ - find: 'user', - filter: { x: 1 }, - readConcern: { - afterOpTime: { ts: twoSecTS, t: term }, - }, - maxTimeMS: 10 * 1000, - })); - - assert.eq(null, res.code); - assert.gt(res.waitedMS, 0); - - insertFunc(); -}; + insertFunc(); + }; -var primary = replTest.getPrimary(); -runTest(primary.getDB('test'), primary); -runTest(replTest.getSecondary().getDB('test'), primary); + var primary = replTest.getPrimary(); + runTest(primary.getDB('test'), primary); + runTest(replTest.getSecondary().getDB('test'), primary); -replTest.stopSet(); + replTest.stopSet(); })(); |