summaryrefslogtreecommitdiff
path: root/jstests/replsets/tenant_migration_shard_merge_read_preference.js
blob: dbfd63ae0a8774ae92ab058fef23f0d2c836ef46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Tests that the shard merge protocol cannot start a migration with readPreference other than
 * primary.
 *
 * @tags: [
 *   incompatible_with_eft,
 *   incompatible_with_macos,
 *   incompatible_with_windows_tls,
 *   featureFlagShardMerge,
 *   requires_persistence,
 *   serverless,
 * ]
 */

import {TenantMigrationTest} from "jstests/replsets/libs/tenant_migration_test.js";
import {
    isShardMergeEnabled,
} from "jstests/replsets/libs/tenant_migration_util.js";

load("jstests/libs/uuid_util.js");

const tenantMigrationTest =
    new TenantMigrationTest({name: jsTestName(), enableRecipientTesting: false});

const donorPrimary = tenantMigrationTest.getDonorPrimary();

if (!isShardMergeEnabled(donorPrimary.getDB("admin"))) {
    tenantMigrationTest.stop();
    jsTestLog("Skipping Shard Merge-specific test");
    quit();
}

const failingMigrationOpts = {
    migrationIdString: extractUUIDFromObject(UUID()),
    readPreference: {mode: "secondary"},
    tenantIds: [ObjectId()]
};
assert.commandFailedWithCode(tenantMigrationTest.startMigration(failingMigrationOpts),
                             ErrorCodes.FailedToSatisfyReadPreference);

const succeessfulMigrationOpts = {
    migrationIdString: extractUUIDFromObject(UUID()),
    readPreference: {mode: "primary"},
    tenantIds: [ObjectId()]
};
assert.commandWorked(tenantMigrationTest.startMigration(succeessfulMigrationOpts));

tenantMigrationTest.stop();