jstests/replsets/tenant_migration_conflicting_recipient_sync_data_cmds.js
/**
 * Tests that if the client runs multiple recipientSyncData commands that would start conflicting
 * migrations, only one of the migrations will start and succeed.
 */
Tests that if the client runs multiple recipientSyncData commands that would start conflicting
migrations, only one of the migrations will start and succeed.
Tests that if the client runs multiple recipientSyncData commands that would start conflicting migrations only one of the migrations will start and succeed .
function testConcurrentConflictingMigration(migrationOpts0, migrationOpts1) {
    const recipientSyncDataThread0 =
        new Thread(runRecipientSyncDataCmd, primary.host, migrationOpts0);
    const recipientSyncDataThread1 =
        new Thread(runRecipientSyncDataCmd, primary.host, migrationOpts1);
    recipientSyncDataThread0.start();
    recipientSyncDataThread1.start();
    const res0 = assert.commandFailed(recipientSyncDataThread0.returnData());
    const res1 = assert.commandFailed(recipientSyncDataThread1.returnData());
    if (res0.code == TestData.stopFailPointErrorCode) {
        assert.commandFailedWithCode(res0, TestData.stopFailPointErrorCode);
        assert.commandFailedWithCode(res1, ErrorCodes.ConflictingOperationInProgress);
        assertNoCertificateOrPrivateKey(res1.errmsg);
        assert.eq(1, configRecipientsColl.count({_id: UUID(migrationOpts0.migrationIdString)}));
        assert.eq(1, getTenantMigrationRecipientCurrentOpEntries(primary, {
                         "instanceID": UUID(migrationOpts0.migrationIdString)
                     }).length);
        if (migrationOpts0.migrationIdString != migrationOpts1.migrationIdString) {
            assert.eq(0, configRecipientsColl.count({_id: UUID(migrationOpts1.migrationIdString)}));
            assert.eq(0, getTenantMigrationRecipientCurrentOpEntries(primary, {
                             "instanceID": UUID(migrationOpts1.migrationIdString)
                         }).length);
        } else if (migrationOpts0.tenantId != migrationOpts1.tenantId) {
            assert.eq(0, configRecipientsColl.count({tenantId: migrationOpts1.tenantId}));
            assert.eq(0, getTenantMigrationRecipientCurrentOpEntries(primary, {
                             tenantId: migrationOpts1.tenantId
                         }).length);
        }
    } else {
        assert.commandFailedWithCode(res0, ErrorCodes.ConflictingOperationInProgress);
        assert.commandFailedWithCode(res1, TestData.stopFailPointErrorCode);
        assertNoCertificateOrPrivateKey(res0.errmsg);
        assert.eq(1, configRecipientsColl.count({_id: UUID(migrationOpts1.migrationIdString)}));
        assert.eq(1, getTenantMigrationRecipientCurrentOpEntries(primary, {
                         "instanceID": UUID(migrationOpts1.migrationIdString)
                     }).length);
        if (migrationOpts0.migrationIdString != migrationOpts1.migrationIdString) {
            assert.eq(0, configRecipientsColl.count({_id: UUID(migrationOpts0.migrationIdString)}));
            assert.eq(0, getTenantMigrationRecipientCurrentOpEntries(primary, {
                             "instanceID": UUID(migrationOpts0.migrationIdString)
                         }).length);
        } else if (migrationOpts0.tenantId != migrationOpts1.tenantId) {
            assert.eq(0, configRecipientsColl.count({tenantId: migrationOpts0.tenantId}));
            assert.eq(0, getTenantMigrationRecipientCurrentOpEntries(primary, {
                             tenantId: migrationOpts0.tenantId
                         }).length);
        }
    }
}
function testConcurrentConflictingMigration ( migrationOpts0 , migrationOpts1 ) { const recipientSyncDataThread0 = new Thread ( runRecipientSyncDataCmd , primary . host , migrationOpts0 ) ; const recipientSyncDataThread1 = new Thread ( runRecipientSyncDataCmd , primary . host , migrationOpts1 ) ; recipientSyncDataThread0 . start ( ) ; recipientSyncDataThread1 . start ( ) ; const res0 = assert . commandFailed ( recipientSyncDataThread0 . returnData ( ) ) ; const res1 = assert . commandFailed ( recipientSyncDataThread1 . returnData ( ) ) ; if ( res0 . code == TestData . stopFailPointErrorCode ) { assert . commandFailedWithCode ( res0 , TestData . stopFailPointErrorCode ) ; assert . commandFailedWithCode ( res1 , ErrorCodes . ConflictingOperationInProgress ) ; assertNoCertificateOrPrivateKey ( res1 . errmsg ) ; assert . eq ( 1 , configRecipientsColl . count ( { _id : UUID ( migrationOpts0 . migrationIdString ) } ) ) ; assert . eq ( 1 , getTenantMigrationRecipientCurrentOpEntries ( primary , { "instanceID" : UUID ( migrationOpts0 . migrationIdString ) } ) . length ) ; if ( migrationOpts0 . migrationIdString != migrationOpts1 . migrationIdString ) { assert . eq ( 0 , configRecipientsColl . count ( { _id : UUID ( migrationOpts1 . migrationIdString ) } ) ) ; assert . eq ( 0 , getTenantMigrationRecipientCurrentOpEntries ( primary , { "instanceID" : UUID ( migrationOpts1 . migrationIdString ) } ) . length ) ; } else if ( migrationOpts0 . tenantId != migrationOpts1 . tenantId ) { assert . eq ( 0 , configRecipientsColl . count ( { tenantId : migrationOpts1 . tenantId } ) ) ; assert . eq ( 0 , getTenantMigrationRecipientCurrentOpEntries ( primary , { tenantId : migrationOpts1 . tenantId } ) . length ) ; } } else { assert . commandFailedWithCode ( res0 , ErrorCodes . ConflictingOperationInProgress ) ; assert . commandFailedWithCode ( res1 , TestData . stopFailPointErrorCode ) ; assertNoCertificateOrPrivateKey ( res0 . errmsg ) ; assert . eq ( 1 , configRecipientsColl . count ( { _id : UUID ( migrationOpts1 . migrationIdString ) } ) ) ; assert . eq ( 1 , getTenantMigrationRecipientCurrentOpEntries ( primary , { "instanceID" : UUID ( migrationOpts1 . migrationIdString ) } ) . length ) ; if ( migrationOpts0 . migrationIdString != migrationOpts1 . migrationIdString ) { assert . eq ( 0 , configRecipientsColl . count ( { _id : UUID ( migrationOpts0 . migrationIdString ) } ) ) ; assert . eq ( 0 , getTenantMigrationRecipientCurrentOpEntries ( primary , { "instanceID" : UUID ( migrationOpts0 . migrationIdString ) } ) . length ) ; } else if ( migrationOpts0 . tenantId != migrationOpts1 . tenantId ) { assert . eq ( 0 , configRecipientsColl . count ( { tenantId : migrationOpts0 . tenantId } ) ) ; assert . eq ( 0 , getTenantMigrationRecipientCurrentOpEntries ( primary , { tenantId : migrationOpts0 . tenantId } ) . length ) ; } } }
Tests that if the client runs multiple recipientSyncData commands that would start conflicting
 migrations, only one of the migrations will start and succeed.
Tests that if the client runs multiple recipientSyncData commands that would start conflicting migrations only one of the migrations will start and succeed .
// Start the conflicting recipientSyncData cmds.