jstests/replsets/change_stream_stepdown.js
// Ensure secondary is up to date and can win an election.
Ensure secondary is up to date and can win an election.
Ensure secondary is up to date and can win an election .
function shellFn(dbName, collName, changeStreamComment, stepUpFn) {
    const primary = db.getMongo();
    assert.soon(() => primary.getDB("admin")
                          .aggregate([
                              {'$currentOp': {}},
                              {
                                  '$match': {
                                      op: 'getmore',
                                      'cursor.originatingCommand.comment': changeStreamComment
                                  }
                              }
                          ])
                          .itcount() == 1);
    const replTest = new ReplSetTest(primary.host);
    const newPrimary = stepUpFn(replTest, replTest.getSecondary());
    const newPrimaryDB = newPrimary.getDB(dbName);
    assert.neq(newPrimary, primary, "Primary didn't change.");
    jsTestLog("Inserting document on new primary");
    assert.commandWorked(newPrimaryDB[collName].insert({_id: 4}), {writeConcern: {w: "majority"}});
}
function shellFn ( dbName , collName , changeStreamComment , stepUpFn ) { const primary = db . getMongo ( ) ; assert . soon ( ( ) => primary . getDB ( "admin" ) . aggregate ( [ { '$currentOp' : { } } , { '$match' : { op : 'getmore' , 'cursor.originatingCommand.comment' : changeStreamComment } } ] ) . itcount ( ) == 1 ) ; const replTest = new ReplSetTest ( primary . host ) ; const newPrimary = stepUpFn ( replTest , replTest . getSecondary ( ) ) ; const newPrimaryDB = newPrimary . getDB ( dbName ) ; assert . neq ( newPrimary , primary , "Primary didn't change." ) ; jsTestLog ( "Inserting document on new primary" ) ; assert . commandWorked ( newPrimaryDB [ collName ] . insert ( { _id : 4 } ) , { writeConcern : { w : "majority" } } ) ; }
Ensure secondary is up to date and can win an election.
Ensure secondary is up to date and can win an election .
// Wait for the getMore to be in progress. // Step down the old primary and wait for new primary.