summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/default_read_pref.js
blob: e5daba20d8ad3a0b5370651561834a44a5c1f6fc (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
50
51
52
53
54
55
56
// Tests that the default read preference is 'unset', and that the slaveOk bit is not set
// on read commands run with an 'unset' read preference.
(function() {

    "use strict";

    var mongo = db.getMongo();
    try {
        var commandsRan = [];
        db._mongo = {
            getSlaveOk: function() {
                return false;
            },
            getReadPrefMode: function() {
                return mongo.getReadPrefMode();
            },
            getReadPref: function() {
                return mongo.getReadPref();
            },
            runCommand: function(db, cmd, opts) {
                commandsRan.push({db: db, cmd: cmd, opts: opts});
                return {ok: 1};
            },
            getMinWireVersion: function() {
                return mongo.getMinWireVersion();
            },
            getMaxWireVersion: function() {
                return mongo.getMaxWireVersion();
            },
            isReplicaSetMember: function() {
                return mongo.isReplicaSetMember();
            },
            isMongos: function() {
                return mongo.isMongos();
            },
            isCausalConsistency: function() {
                return false;
            },
            getClusterTime: function() {
                return null;
            },
        };
        db._session = new _DummyDriverSession(db._mongo);

        db.runReadCommand({ping: 1});
        assert.eq(commandsRan.length, 1);
        assert.docEq(commandsRan[0].cmd, {ping: 1}, "The command should not have been wrapped.");
        assert.eq(
            commandsRan[0].opts & DBQuery.Option.slaveOk, 0, "The slaveOk bit should not be set.");

    } finally {
        db._mongo = mongo;
        db._session = new _DummyDriverSession(mongo);
    }

})();