jstests/replsets/tenant_migration_donor_resume_on_stepup_and_restart.js
/**
 * Starts a migration and sets the passed in failpoint, then either waits for the failpoint or lets
 * the migration run successfully and interrupts the donor using the 'interruptFunc'. After
 * restarting, check the to see if the donorDoc data has persisted.
 */
Starts a migration and sets the passed in failpoint, then either waits for the failpoint or lets
the migration run successfully and interrupts the donor using the 'interruptFunc'. After
restarting, check the to see if the donorDoc data has persisted.
Starts a migration and sets the passed in failpoint then either waits for the failpoint or lets the migration run successfully and interrupts the donor using the ' interruptFunc ' . After restarting check the to see if the donorDoc data has persisted .
function testStateDocPersistenceOnFailover(interruptFunc, fpName, isShutdown = false) {
    const donorRst =
        new ReplSetTest({nodes: 3, name: "donorRst", nodeOptions: migrationX509Options.donor});
    donorRst.startSet();
    donorRst.initiate();
    const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), donorRst});
    const migrationId = UUID();
    const migrationOpts = {
        migrationIdString: extractUUIDFromObject(migrationId),
        tenantId: kTenantId,
        recipientConnString: tenantMigrationTest.getRecipientConnString(),
    };
    let donorPrimary = tenantMigrationTest.getDonorPrimary();
    let fp;
    if (fpName) {
        fp = configureFailPoint(donorPrimary, fpName);
        assert.commandWorked(tenantMigrationTest.startMigration(migrationOpts));
        fp.wait();
    } else {
        TenantMigrationTest.assertCommitted(tenantMigrationTest.runMigration(migrationOpts));
    }
    let configDonorsColl = donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS);
    let donorDocBeforeFailover = configDonorsColl.findOne({tenantId: kTenantId});
    interruptFunc(tenantMigrationTest.getDonorRst());
    if (fp && !isShutdown) {
        fp.off();
    }
    donorPrimary = tenantMigrationTest.getDonorPrimary();
    configDonorsColl = donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS);
    let donorDocAfterFailover = configDonorsColl.findOne({tenantId: kTenantId});
    assert.eq(donorDocBeforeFailover._id, donorDocAfterFailover._id);
    assert.eq(donorDocBeforeFailover.recipientConnString,
              donorDocAfterFailover.recipientConnString);
    assert.eq(donorDocBeforeFailover.readPreference, donorDocAfterFailover.readPreference);
    assert.eq(donorDocBeforeFailover.startMigrationDonorTimestamp,
              donorDocAfterFailover.startMigrationDonorTimestamp);
    assert.eq(donorDocBeforeFailover.migration, donorDocAfterFailover.migration);
    assert.eq(donorDocBeforeFailover.tenantId, donorDocAfterFailover.tenantId);
    assert.eq(donorDocBeforeFailover.donorCertificateForRecipient,
              donorDocAfterFailover.donorCertificateForRecipient);
    assert.eq(donorDocBeforeFailover.recipientCertificateForDonor,
              donorDocAfterFailover.recipientCertificateForDonor);
    assert.eq(donorDocBeforeFailover.migrationStart, donorDocAfterFailover.migrationStart);
    tenantMigrationTest.stop();
    donorRst.stopSet();
}
function testStateDocPersistenceOnFailover ( interruptFunc , fpName , isShutdown = false ) { const donorRst = new ReplSetTest ( { nodes : 3 , name : "donorRst" , nodeOptions : migrationX509Options . donor } ) ; donorRst . startSet ( ) ; donorRst . initiate ( ) ; const tenantMigrationTest = new TenantMigrationTest ( { name : jsTestName ( ) , donorRst } ) ; const migrationId = UUID ( ) ; const migrationOpts = { migrationIdString : extractUUIDFromObject ( migrationId ) , tenantId : kTenantId , recipientConnString : tenantMigrationTest . getRecipientConnString ( ) , } ; let donorPrimary = tenantMigrationTest . getDonorPrimary ( ) ; let fp ; if ( fpName ) { fp = configureFailPoint ( donorPrimary , fpName ) ; assert . commandWorked ( tenantMigrationTest . startMigration ( migrationOpts ) ) ; fp . wait ( ) ; } else { TenantMigrationTest . assertCommitted ( tenantMigrationTest . runMigration ( migrationOpts ) ) ; } let configDonorsColl = donorPrimary . getCollection ( TenantMigrationTest . kConfigDonorsNS ) ; let donorDocBeforeFailover = configDonorsColl . findOne ( { tenantId : kTenantId } ) ; interruptFunc ( tenantMigrationTest . getDonorRst ( ) ) ; if ( fp && ! isShutdown ) { fp . off ( ) ; } donorPrimary = tenantMigrationTest . getDonorPrimary ( ) ; configDonorsColl = donorPrimary . getCollection ( TenantMigrationTest . kConfigDonorsNS ) ; let donorDocAfterFailover = configDonorsColl . findOne ( { tenantId : kTenantId } ) ; assert . eq ( donorDocBeforeFailover . _id , donorDocAfterFailover . _id ) ; assert . eq ( donorDocBeforeFailover . recipientConnString , donorDocAfterFailover . recipientConnString ) ; assert . eq ( donorDocBeforeFailover . readPreference , donorDocAfterFailover . readPreference ) ; assert . eq ( donorDocBeforeFailover . startMigrationDonorTimestamp , donorDocAfterFailover . startMigrationDonorTimestamp ) ; assert . eq ( donorDocBeforeFailover . migration , donorDocAfterFailover . migration ) ; assert . eq ( donorDocBeforeFailover . tenantId , donorDocAfterFailover . tenantId ) ; assert . eq ( donorDocBeforeFailover . donorCertificateForRecipient , donorDocAfterFailover . donorCertificateForRecipient ) ; assert . eq ( donorDocBeforeFailover . recipientCertificateForDonor , donorDocAfterFailover . recipientCertificateForDonor ) ; assert . eq ( donorDocBeforeFailover . migrationStart , donorDocAfterFailover . migrationStart ) ; tenantMigrationTest . stop ( ) ; donorRst . stopSet ( ) ; }
Starts a migration and sets the passed in failpoint, then either waits for the failpoint or lets
 the migration run successfully and interrupts the donor using the 'interruptFunc'.
Starts a migration and sets the passed in failpoint then either waits for the failpoint or lets the migration run successfully and interrupts the donor using the ' interruptFunc ' .
// If we passed in a valid failpoint we set it, otherwise we let the migration run normally. // Turn off failpoint in order to allow the migration to resume after stepup. // Check persisted fields in the donor doc.