Skip to content

Commit 3654969

Browse files
ldennisevergreen
authored andcommitted
SERVER-42262: Repeat stepdown and freeze on test shutdown validation
1 parent 2411d2f commit 3654969

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

jstests/libs/override_methods/validate_collections_on_shutdown.js

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,44 @@ MongoRunner.validateCollectionsCallback = function(port) {
5555
// been initialized yet, then it cannot get elected.
5656
const kFreezeTimeSecs = 24 * 60 * 60; // 24 hours.
5757

58-
assert.commandWorkedOrFailedWithCode(
59-
conn.adminCommand({replSetStepDown: kFreezeTimeSecs, force: true}), [
60-
ErrorCodes.NotMaster,
61-
ErrorCodes.NotYetInitialized,
62-
ErrorCodes.Unauthorized
63-
]);
58+
assert.soon(
59+
() => {
60+
assert.commandWorkedOrFailedWithCode(
61+
conn.adminCommand(
62+
{replSetStepDown: kFreezeTimeSecs, force: true}),
63+
[
64+
ErrorCodes.NotMaster,
65+
ErrorCodes.NotYetInitialized,
66+
ErrorCodes.Unauthorized
67+
]);
68+
const res = conn.adminCommand({replSetFreeze: kFreezeTimeSecs});
69+
assert.commandWorkedOrFailedWithCode(res, [
70+
ErrorCodes.NotYetInitialized,
71+
ErrorCodes.Unauthorized,
72+
ErrorCodes.NotSecondary
73+
]);
6474

65-
assert.commandWorkedOrFailedWithCode(
66-
conn.adminCommand({replSetFreeze: kFreezeTimeSecs}), [
67-
ErrorCodes.NotYetInitialized,
68-
ErrorCodes.Unauthorized,
69-
// We include "NotSecondary" because if replSetStepDown receives
70-
// "NotYetInitialized", then this command will fail with
71-
// "NotSecondary". This is why this is a "best-effort".
72-
ErrorCodes.NotSecondary
73-
]);
75+
// If 'replSetFreeze' succeeds or fails with NotYetInitialized or
76+
// Unauthorized, we do not need to retry the command because
77+
// retrying will not work if the replica set is not yet
78+
// initialized or if we are not authorized to run the command.
79+
// This is why this is a "best-effort".
80+
if (res.ok === 1 || res.code !== ErrorCodes.NotSecondary) {
81+
return true;
82+
}
83+
84+
// We only retry on NotSecondary error because 'replSetFreeze'
85+
// could fail with NotSecondary if the node is currently primary
86+
// or running for election. This could happen if there is a
87+
// concurrent election running in parallel with the
88+
// 'replSetStepDown' sent above.
89+
jsTestLog(
90+
"Retrying 'replSetStepDown' and 'replSetFreeze' in port " +
91+
conn.port + " res: " + tojson(res));
92+
return false;
93+
},
94+
"Timed out running 'replSetStepDown' and 'replSetFreeze' node in " +
95+
"port " + conn.port);
7496
}
7597
})
7698
.then("getting the list of databases",

0 commit comments

Comments
 (0)