load("jstests/libs/fail_point_util.js");
let rst = new ReplSetTest({nodes: 3, useBridge: true});
rst.startSet();
rst.initiate();
let primary = rst.getPrimary();
let coll = primary.getDB("test")["test"];
let config = rst.getReplSetConfigFromNode(0);
let origVersion = config.version;
jsTestLog("Isolating the old primary.");
primary.disconnect([rst.nodes[2]]);
let fp1 = configureFailPoint(rst.nodes[1], "blockHeartbeatReconfigFinish");
config.version = origVersion + 1;
jsTestLog("Reconfig on old primary to advance config version to: " + config.version);
let res = primary.adminCommand({replSetReconfig: config, maxTimeMS: 2000});
assert.commandFailedWithCode(res, ErrorCodes.MaxTimeMSExpired);
primary.disconnect([rst.nodes[1]]);
let fp2 = configureFailPoint(rst.nodes[0], "blockHeartbeatReconfigFinish");
jsTestLog("Stepping up node 2.");
assert.soonNoExcept(() => {
assert.commandWorked(rst.nodes[2].adminCommand({replSetStepUp: 1}));
return true;
});
assert.soonNoExcept(() => {return rst.nodes[2].adminCommand({isMaster: 1}).ismaster});
fp1.off();
assert.soon(() => isConfigCommitted(rst.nodes[2]));
rst.nodes[1].disconnect(rst.nodes[2]);
jsTestLog("Reconnecting old primary to new primary");
primary.reconnect([rst.nodes[2]]);
jsTestLog("Doing a reconfig on node 2");
config = rst.getReplSetConfigFromNode(2);
config.version = origVersion + 1;
assert.commandWorked(rst.nodes[2].adminCommand({replSetReconfig: config}));
primary.reconnect([rst.nodes[1], rst.nodes[2]]);
fp2.off();
rst.stopSet();