summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/internal_validate_features_as_primary.js
blob: 9f6e2429661b2b07f6876841342d740112a843e5 (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
/**
 * Tests that the internalValidateFeaturesAsPrimary server parameter
 * and the deprecated alias internalValidateFeaturesAsMaster both work.
 * @tags: [
 * ]
 */
(function() {
"use strict";

// internalValidateFeaturesAsPrimary can be set via startup parameter.
let conn = MongoRunner.runMongod({setParameter: "internalValidateFeaturesAsPrimary=0"});
assert.neq(null, conn, "mongod was unable to start up");
let res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsPrimary: 1});
assert.commandWorked(res);
assert.eq(res.internalValidateFeaturesAsPrimary, false);

// Even though we set internalValidateFeaturesAsPrimary, verify that calling
// getParameter with the deprecated alias internalValidateFeaturesAsMaster works
// and uses the value we set for internalValidateFeaturesAsPrimary.
res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});
assert.commandWorked(res);
assert.eq(res.internalValidateFeaturesAsMaster, false);

// Use of deprecated parameter shows deprecation message.
let joinShell = startParallelShell(
    "db.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});", conn.port);
joinShell();
assert(rawMongoProgramOutput().match(
    "\"Use of deprecated server parameter name\",\"attr\":{\"deprecatedName\":\"internalValidateFeaturesAsMaster\""));
MongoRunner.stopMongod(conn);

// internalValidateFeaturesAsMaster can be set via startup parameter.
conn = MongoRunner.runMongod({setParameter: "internalValidateFeaturesAsMaster=1"});
assert.neq(null, conn, "mongod was unable to start up");
res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsMaster: 1});
assert.commandWorked(res);
assert.eq(res.internalValidateFeaturesAsMaster, true);

// Verify that calling getParameter with internalValidateFeaturesAsPrimary
// uses the value we set for internalValidateFeaturesAsMaster.
res = conn.adminCommand({getParameter: 1, internalValidateFeaturesAsPrimary: 1});
assert.commandWorked(res);
assert.eq(res.internalValidateFeaturesAsPrimary, true);
MongoRunner.stopMongod(conn);

// internalValidateFeaturesAsPrimary cannot be set with --replSet.
assert.throws(() => MongoRunner.runMongod(
                  {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"}),
              [],
              "mongod was unexpectedly able to start up");

assert.throws(() => MongoRunner.runMongod(
                  {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=1"}),
              [],
              "mongod was unexpectedly able to start up");

// Correct error message is logged based on parameter name.
conn = MongoRunner.runMongod({});
joinShell = startParallelShell(() => {
    assert.throws(
        () => MongoRunner.runMongod(
            {replSet: "replSetName", setParameter: "internalValidateFeaturesAsPrimary=0"}));
}, conn.port);
joinShell();
let joinShellOutput = rawMongoProgramOutput();
assert(joinShellOutput.match(
    "Cannot specify both internalValidateFeaturesAsPrimary and replication.replSet"));
assert(!joinShellOutput.match(
    "Cannot specify both internalValidateFeaturesAsMaster and replication.replSet"));

clearRawMongoProgramOutput();
joinShell = startParallelShell(() => {
    assert.throws(
        () => MongoRunner.runMongod(
            {replSet: "replSetName", setParameter: "internalValidateFeaturesAsMaster=0"}));
}, conn.port);
joinShell();
joinShellOutput = rawMongoProgramOutput();
assert(joinShellOutput.match(
    "Cannot specify both internalValidateFeaturesAsMaster and replication.replSet"));
assert(!joinShellOutput.match(
    "Cannot specify both internalValidateFeaturesAsPrimary and replication.replSet"));

MongoRunner.stopMongod(conn);

// internalValidateFeaturesAsPrimary cannot be set via runtime parameter.
conn = MongoRunner.runMongod({});
assert.commandFailed(conn.adminCommand({setParameter: 1, internalValidateFeaturesAsPrimary: true}));
assert.commandFailed(
    conn.adminCommand({setParameter: 1, internalValidateFeaturesAsPrimary: false}));
MongoRunner.stopMongod(conn);
}());