1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// 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.settings.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
var res = assert.commandFailed(testDB.runCommand({
find: 'user',
filter: { x: 1 },
$readConcern: {
afterOpTime: { ts: twoSecTS, term: 0 }
},
maxTimeMS: 1000
}));
assert.eq(50, res.code); // ErrorCodes::ExceededTimeLimit
assert.gt(res.waitedMS, 500);
assert.lt(res.waitedMS, 2500);
// Test read on future afterOpTime 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 },
$readConcern: {
afterOpTime: { ts: twoSecTS, term: 0 },
maxTimeMS: 10 * 1000
}
}));
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();
})();
|