summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/benchrun_read_pref_mode.js
blob: 0487335217037b0007b69a3bb119ea8817a0bd27 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 * Verifies that readPrefMode param works for find/fineOne/query ops in benchRun().
 *
 * @tags: [requires_replication]
 */

(function() {
"use strict";

const rs = new ReplSetTest({nodes: 2});
rs.startSet();
rs.initiate();

const primary = rs.getPrimary();
const secondary = rs.getSecondary();
const collName = primary.getDB(jsTestName()).getCollection("coll").getFullName();

const verifyNoError = res => {
    assert.eq(res.errCount, 0);
    assert.gt(res.totalOps, 0);
};

const benchArgArray = [
    {
        ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "primary"}],
        parallel: 1,
        host: primary.host
    },
    {
        ops: [{
            op: "findOne",
            readCmd: true,
            query: {},
            ns: collName,
            readPrefMode: "primaryPreferred"
        }],
        parallel: 1,
        host: primary.host
    },
    {
        ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "secondary"}],
        parallel: 1,
        host: secondary.host
    },
    {
        ops: [{
            op: "findOne",
            readCmd: true,
            query: {},
            ns: collName,
            readPrefMode: "secondaryPreferred"
        }],
        parallel: 1,
        host: secondary.host
    },
    {
        ops: [{op: "query", readCmd: true, query: {}, ns: collName, readPrefMode: "nearest"}],
        parallel: 1,
        host: secondary.host
    },
];

benchArgArray.forEach(benchArg => verifyNoError(benchRun(benchArg)));

const invalidArgAndError = [
    {
        benchArg: {
            ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: 1}],
            parallel: 1,
            host: primary.host
        },
        error: ErrorCodes.BadValue
    },
    {
        benchArg: {
            ops:
                [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "invalidPref"}],
            parallel: 1,
            host: primary.host
        },
        error: ErrorCodes.BadValue
    },
    {
        benchArg: {
            ops: [
                {op: "insert", writeCmd: true, doc: {a: 1}, ns: collName, readPrefMode: "primary"}
            ],
            parallel: 1,
            host: primary.host
        },
        error: ErrorCodes.InvalidOptions
    },
];

invalidArgAndError.forEach(
    argAndError => assert.throwsWithCode(() => benchRun(argAndError.benchArg), argAndError.error));

rs.stopSet();
})();