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
|
(function() {
'use strict';
/**
* Performs basic checks on the configureFailPoint command. Also check
* mongo/util/fail_point_test.cpp for unit tests.
*
* @param adminDB {DB} the admin database database object
*/
function runTest(adminDB) {
function expectFailPointState(fpState, expectedMode, expectedData) {
assert.eq(expectedMode, fpState.mode);
// Check that all expected data is present.
for (var field in expectedData) { // Valid only for 1 level field checks
assert.eq(expectedData[field], fpState.data[field]);
}
// Check that all present data is expected.
for (field in fpState.data) {
assert.eq(expectedData[field], fpState.data[field]);
}
}
var res;
// A failpoint's state can be read through getParameter by prefixing its name with
// "failpoint"
// Test non-existing fail point
assert.commandFailed(
adminDB.runCommand({configureFailPoint: 'fpNotExist', mode: 'alwaysOn', data: {x: 1}}));
// Test bad mode string
assert.commandFailed(
adminDB.runCommand({configureFailPoint: 'dummy', mode: 'badMode', data: {x: 1}}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 0, {});
// Test bad mode obj
assert.commandFailed(
adminDB.runCommand({configureFailPoint: 'dummy', mode: {foo: 3}, data: {x: 1}}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 0, {});
// Test bad mode type
assert.commandFailed(
adminDB.runCommand({configureFailPoint: 'dummy', mode: true, data: {x: 1}}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 0, {});
// Test bad data type
assert.commandFailed(
adminDB.runCommand({configureFailPoint: 'dummy', mode: 'alwaysOn', data: 'data'}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 0, {});
// Test setting mode to off.
assert.commandWorked(adminDB.runCommand({configureFailPoint: 'dummy', mode: 'off'}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 0, {});
// Test setting mode to skip.
assert.commandWorked(adminDB.runCommand({configureFailPoint: 'dummy', mode: {skip: 2}}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 4, {});
// Test good command w/ data
assert.commandWorked(
adminDB.runCommand({configureFailPoint: 'dummy', mode: 'alwaysOn', data: {x: 1}}));
res = adminDB.runCommand({getParameter: 1, "failpoint.dummy": 1});
assert.commandWorked(res);
expectFailPointState(res["failpoint.dummy"], 1, {x: 1});
}
var conn = MongoRunner.runMongod();
runTest(conn.getDB('admin'));
MongoRunner.stopMongod(conn);
///////////////////////////////////////////////////////////
// Test mongos
var st = new ShardingTest({shards: 1});
runTest(st.s.getDB('admin'));
st.stop();
})();
|