jstests/replsets/tenant_migration_donor_state_machine.js
/**
 * Runs the donorForgetMigration command and asserts that the TenantMigrationAccessBlocker and donor
 * state document are eventually removed from the donor.
 */
Runs the donorForgetMigration command and asserts that the TenantMigrationAccessBlocker and donor
state document are eventually removed from the donor.
Runs the donorForgetMigration command and asserts that the TenantMigrationAccessBlocker and donor state document are eventually removed from the donor .
function testDonorForgetMigrationAfterMigrationCompletes(
    donorRst, recipientRst, migrationId, tenantId) {
    jsTest.log("Test donorForgetMigration after the migration completes");
    const donorPrimary = donorRst.getPrimary();
    const recipientPrimary = recipientRst.getPrimary();
    assert.commandWorked(
        donorPrimary.adminCommand({donorForgetMigration: 1, migrationId: migrationId}));
    expectedNumRecipientForgetMigrationCmdSent++;
    const recipientForgetMigrationMetrics =
        recipientPrimary.adminCommand({serverStatus: 1}).metrics.commands.recipientForgetMigration;
    assert.eq(recipientForgetMigrationMetrics.failed, 0);
    assert.eq(recipientForgetMigrationMetrics.total, expectedNumRecipientForgetMigrationCmdSent);
    donorRst.nodes.forEach((node) => {
        assert.soon(() => null ==
                        TenantMigrationUtil.getTenantMigrationAccessBlocker({donorNode: node}));
    });
    assert.soon(() => 0 === donorPrimary.getCollection(TenantMigrationTest.kConfigDonorsNS).count({
        tenantId: tenantId
    }));
    assert.soon(() => 0 ===
                    donorPrimary.adminCommand({serverStatus: 1})
                        .repl.primaryOnlyServices.TenantMigrationDonorService.numInstances);
    const donorRecipientMonitorPoolStats =
        donorPrimary.adminCommand({connPoolStats: 1}).replicaSets;
    assert.eq(Object.keys(donorRecipientMonitorPoolStats).length, 0);
    recipientRst.nodes.forEach((node) => {
        assert.soon(() => null ==
                        TenantMigrationUtil.getTenantMigrationAccessBlocker({recipientNode: node}));
    });
    assert.soon(() => 0 ===
                    recipientPrimary.getCollection(TenantMigrationTest.kConfigRecipientsNS).count({
                        tenantId: tenantId
                    }));
    assert.soon(() => 0 ===
                    recipientPrimary.adminCommand({serverStatus: 1})
                        .repl.primaryOnlyServices.TenantMigrationRecipientService.numInstances);
    const recipientRecipientMonitorPoolStats =
        recipientPrimary.adminCommand({connPoolStats: 1}).replicaSets;
    assert.eq(Object.keys(recipientRecipientMonitorPoolStats).length, 0);
}
function testDonorForgetMigrationAfterMigrationCompletes ( donorRst , recipientRst , migrationId , tenantId ) { jsTest . log ( "Test donorForgetMigration after the migration completes" ) ; const donorPrimary = donorRst . getPrimary ( ) ; const recipientPrimary = recipientRst . getPrimary ( ) ; assert . commandWorked ( donorPrimary . adminCommand ( { donorForgetMigration : 1 , migrationId : migrationId } ) ) ; expectedNumRecipientForgetMigrationCmdSent ++ ; const recipientForgetMigrationMetrics = recipientPrimary . adminCommand ( { serverStatus : 1 } ) . metrics . commands . recipientForgetMigration ; assert . eq ( recipientForgetMigrationMetrics . failed , 0 ) ; assert . eq ( recipientForgetMigrationMetrics . total , expectedNumRecipientForgetMigrationCmdSent ) ; donorRst . nodes . forEach ( ( node ) => { assert . soon ( ( ) => null == TenantMigrationUtil . getTenantMigrationAccessBlocker ( { donorNode : node } ) ) ; } ) ; assert . soon ( ( ) => 0 === donorPrimary . getCollection ( TenantMigrationTest . kConfigDonorsNS ) . count ( { tenantId : tenantId } ) ) ; assert . soon ( ( ) => 0 === donorPrimary . adminCommand ( { serverStatus : 1 } ) . repl . primaryOnlyServices . TenantMigrationDonorService . numInstances ) ; const donorRecipientMonitorPoolStats = donorPrimary . adminCommand ( { connPoolStats : 1 } ) . replicaSets ; assert . eq ( Object . keys ( donorRecipientMonitorPoolStats ) . length , 0 ) ; recipientRst . nodes . forEach ( ( node ) => { assert . soon ( ( ) => null == TenantMigrationUtil . getTenantMigrationAccessBlocker ( { recipientNode : node } ) ) ; } ) ; assert . soon ( ( ) => 0 === recipientPrimary . getCollection ( TenantMigrationTest . kConfigRecipientsNS ) . count ( { tenantId : tenantId } ) ) ; assert . soon ( ( ) => 0 === recipientPrimary . adminCommand ( { serverStatus : 1 } ) . repl . primaryOnlyServices . TenantMigrationRecipientService . numInstances ) ; const recipientRecipientMonitorPoolStats = recipientPrimary . adminCommand ( { connPoolStats : 1 } ) . replicaSets ; assert . eq ( Object . keys ( recipientRecipientMonitorPoolStats ) . length , 0 ) ; }
Runs the donorForgetMigration command and asserts that the TenantMigrationAccessBlocker and donor
 state document are eventually removed from the donor.
Runs the donorForgetMigration command and asserts that the TenantMigrationAccessBlocker and donor state document are eventually removed from the donor .
// Wait for garbage collection on donor. // Wait for garbage collection on recipient.