-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathfail_point.js
137 lines (112 loc) · 5.16 KB
/
fail_point.js
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// @tags: [requires_sharding]
/**
* Performs basic checks on the configureFailPoint and waitForFailPoint command.
* Also check mongo/util/fail_point_test.cpp for unit tests.
*
* @param adminDB {DB} the admin database database object
*/
import {kDefaultWaitForFailPointTimeout} from "jstests/libs/fail_point_util.js";
import {ShardingTest} from "jstests/libs/shardingtest.js";
function runBasicTest(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});
// Test that the timeout for waitForFailPoint can be set via maxTimeMS.
var configureFailPointRes = adminDB.runCommand({configureFailPoint: 'dummy', mode: 'alwaysOn'});
assert.commandWorked(configureFailPointRes);
assert.commandFailedWithCode(adminDB.adminCommand({
waitForFailPoint: "dummy",
timesEntered: configureFailPointRes.count + 1,
maxTimeMS: 10
}),
ErrorCodes.MaxTimeMSExpired);
// Test that waitForFailPoint throws an error when maxTimeMS is not provided.
assert.commandFailedWithCode(adminDB.adminCommand({waitForFailPoint: "dummy", timesEntered: 1}),
[ErrorCodes.FailedToParse, ErrorCodes.IDLFailedToParse]);
}
// Test the parameter handling.
var conn = MongoRunner.runMongod();
runBasicTest(conn.getDB('admin'));
MongoRunner.stopMongod(conn);
var st = new ShardingTest({shards: 1});
runBasicTest(st.s.getDB('admin'));
// Test the functionality of the commands.
const testDB = st.shard0.getDB("test");
const testColl = testDB["user"];
const failPointName = "hangAfterCollectionInserts";
// Turn on the fail point and check that the returned count is 0.
var configureFailPointRes = assert.commandWorked(testDB.adminCommand({
configureFailPoint: failPointName,
mode: "alwaysOn",
data: {collectionNS: testColl.getFullName()}
}));
assert.eq(0, configureFailPointRes.count);
const joinHungWrite = startParallelShell(() => {
assert.commandWorked(db.getSiblingDB("test").user.insert({_id: 0}));
}, st.rs0.getPrimary().port);
// Wait for the fail point to be entered.
assert.commandWorked(testDB.adminCommand({
waitForFailPoint: failPointName,
timesEntered: 1,
maxTimeMS: kDefaultWaitForFailPointTimeout
}));
// Turn off the fail point
configureFailPointRes =
assert.commandWorked(testDB.adminCommand({configureFailPoint: failPointName, mode: "off"}));
assert.lte(1, configureFailPointRes.count);
joinHungWrite();
st.stop();