jstests/replsets/tenant_migration_recipient_resume_on_stepup_and_restart.js
/**
 * Runs the donorStartMigration command to start a migration, and interrupts the migration on the
 * recipient using the 'interruptFunc' after the migration starts on the recipient side, and
 * asserts that migration eventually commits.
 * @param {recipientRestarted} bool is needed to properly assert the tenant migrations stat count.
 */
Runs the donorStartMigration command to start a migration, and interrupts the migration on the
recipient using the 'interruptFunc' after the migration starts on the recipient side, and
asserts that migration eventually commits.
@param {recipientRestarted} bool is needed to properly assert the tenant migrations stat count.
Runs the donorStartMigration command to start a migration and interrupts the migration on the recipient using the ' interruptFunc ' after the migration starts on the recipient side and asserts that migration eventually commits . @param { recipientRestarted } bool is needed to properly assert the tenant migrations stat count .
function testRecipientSyncDataInterrupt(interruptFunc, recipientRestarted) {
    const recipientRst = new ReplSetTest(
        {nodes: 3, name: "recipientRst", nodeOptions: migrationX509Options.recipient});
    recipientRst.startSet();
    recipientRst.initiate();
    const tenantMigrationTest = new TenantMigrationTest({name: jsTestName(), recipientRst});
    const donorRst = tenantMigrationTest.getDonorRst();
    const donorPrimary = tenantMigrationTest.getDonorPrimary();
    let recipientPrimary = tenantMigrationTest.getRecipientPrimary();
    const migrationId = UUID();
    const migrationOpts = {
        migrationIdString: extractUUIDFromObject(migrationId),
        tenantId: kTenantId,
        recipientConnString: tenantMigrationTest.getRecipientConnString(),
    };
    const donorRstArgs = TenantMigrationUtil.createRstArgs(donorRst);
    const runMigrationThread =
        new Thread(TenantMigrationUtil.runMigrationAsync, migrationOpts, donorRstArgs);
    runMigrationThread.start();
    assert.soon(
        () => recipientPrimary.adminCommand({currentOp: true, desc: "tenant recipient migration"})
                  .inprog.length > 0);
    sleep(Math.random() * kMaxSleepTimeMS);
    interruptFunc(recipientRst);
    TenantMigrationTest.assertCommitted(runMigrationThread.returnData());
    tenantMigrationTest.waitForDonorNodesToReachState(donorRst.nodes,
                                                      migrationId,
                                                      migrationOpts.tenantId,
                                                      TenantMigrationTest.DonorState.kCommitted);
    assert.commandWorked(tenantMigrationTest.forgetMigration(migrationOpts.migrationIdString));
    tenantMigrationTest.awaitTenantMigrationStatsCounts(donorPrimary,
                                                        {totalSuccessfulMigrationsDonated: 1});
    recipientPrimary = tenantMigrationTest.getRecipientPrimary();  
    if (!recipientRestarted) {
        tenantMigrationTest.awaitTenantMigrationStatsCounts(recipientPrimary,
                                                            {totalSuccessfulMigrationsReceived: 1});
    } else {
        const stats = tenantMigrationTest.getTenantMigrationStats(recipientPrimary);
        assert(1 == stats.totalSuccessfulMigrationsReceived ||
               0 == stats.totalSuccessfulMigrationsReceived);
    }
    tenantMigrationTest.stop();
    recipientRst.stopSet();
}
function testRecipientSyncDataInterrupt ( interruptFunc , recipientRestarted ) { const recipientRst = new ReplSetTest ( { nodes : 3 , name : "recipientRst" , nodeOptions : migrationX509Options . recipient } ) ; recipientRst . startSet ( ) ; recipientRst . initiate ( ) ; const tenantMigrationTest = new TenantMigrationTest ( { name : jsTestName ( ) , recipientRst } ) ; const donorRst = tenantMigrationTest . getDonorRst ( ) ; const donorPrimary = tenantMigrationTest . getDonorPrimary ( ) ; let recipientPrimary = tenantMigrationTest . getRecipientPrimary ( ) ; const migrationId = UUID ( ) ; const migrationOpts = { migrationIdString : extractUUIDFromObject ( migrationId ) , tenantId : kTenantId , recipientConnString : tenantMigrationTest . getRecipientConnString ( ) , } ; const donorRstArgs = TenantMigrationUtil . createRstArgs ( donorRst ) ; const runMigrationThread = new Thread ( TenantMigrationUtil . runMigrationAsync , migrationOpts , donorRstArgs ) ; runMigrationThread . start ( ) ; assert . soon ( ( ) => recipientPrimary . adminCommand ( { currentOp : true , desc : "tenant recipient migration" } ) . inprog . length > 0 ) ; sleep ( Math . random ( ) * kMaxSleepTimeMS ) ; interruptFunc ( recipientRst ) ; TenantMigrationTest . assertCommitted ( runMigrationThread . returnData ( ) ) ; tenantMigrationTest . waitForDonorNodesToReachState ( donorRst . nodes , migrationId , migrationOpts . tenantId , TenantMigrationTest . DonorState . kCommitted ) ; assert . commandWorked ( tenantMigrationTest . forgetMigration ( migrationOpts . migrationIdString ) ) ; tenantMigrationTest . awaitTenantMigrationStatsCounts ( donorPrimary , { totalSuccessfulMigrationsDonated : 1 } ) ; recipientPrimary = tenantMigrationTest . getRecipientPrimary ( ) ; if ( ! recipientRestarted ) { tenantMigrationTest . awaitTenantMigrationStatsCounts ( recipientPrimary , { totalSuccessfulMigrationsReceived : 1 } ) ; } else { const stats = tenantMigrationTest . getTenantMigrationStats ( recipientPrimary ) ; assert ( 1 == stats . totalSuccessfulMigrationsReceived || 0 == stats . totalSuccessfulMigrationsReceived ) ; } tenantMigrationTest . stop ( ) ; recipientRst . stopSet ( ) ; }
Runs the donorStartMigration command to start a migration, and interrupts the migration on the
 recipient using the 'interruptFunc' after the migration starts on the recipient side, and
 asserts that migration eventually commits.
Runs the donorStartMigration command to start a migration and interrupts the migration on the recipient using the ' interruptFunc ' after the migration starts on the recipient side and asserts that migration eventually commits .
// Wait for recipientSyncData command to start. // Could change after interrupt. // In full restart the count could be lost completely.