summaryrefslogtreecommitdiff
path: root/jstests/replsets/await_replication_timeout.js
blob: b0fb605567d15724fffc483415266a0da956d2f7 (plain)
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
// Tests timeout behavior of waiting for write concern as well as its interaction with maxTimeMs

(function() {
    "use strict";

    var exceededTimeLimitCode = 50;
    var writeConcernFailedCode = 64;
    var replTest = new ReplSetTest({nodes: 3});
    replTest.startSet();
    replTest.initiate();
    replTest.stop(
        0);  // Make sure that there are only 2 nodes up so w:3 writes will always time out
    var primary = replTest.getPrimary();
    var testDB = primary.getDB('test');

    // Test wtimeout
    var res = testDB.runCommand(
        {insert: 'foo', documents: [{a: 1}], writeConcern: {w: 3, wtimeout: 1000}});
    assert.commandWorked(res);  // Commands with write concern errors still report success.
    assert.eq(writeConcernFailedCode, res.writeConcernError.code);

    // Test maxTimeMS timeout
    res = testDB.runCommand(
        {insert: 'foo', documents: [{a: 1}], writeConcern: {w: 3}, maxTimeMS: 1000});
    assert.commandWorked(res);  // Commands with write concern errors still report success.
    assert.eq(exceededTimeLimitCode, res.writeConcernError.code);

    // Test with wtimeout < maxTimeMS
    res = testDB.runCommand({
        insert: 'foo',
        documents: [{a: 1}],
        writeConcern: {w: 3, wtimeout: 1000},
        maxTimeMS: 10 * 1000
    });
    assert.commandWorked(res);  // Commands with write concern errors still report success.
    assert.eq(writeConcernFailedCode, res.writeConcernError.code);

    // Test with wtimeout > maxTimeMS
    res = testDB.runCommand({
        insert: 'foo',
        documents: [{a: 1}],
        writeConcern: {w: 3, wtimeout: 10 * 1000},
        maxTimeMS: 1000
    });
    assert.commandWorked(res);  // Commands with write concern errors still report success.
    assert.eq(exceededTimeLimitCode, res.writeConcernError.code);
    replTest.stopSet();

})();