From 45ed8d2e32bf5bf5831c95fd088976ef5e44e56a Mon Sep 17 00:00:00 2001 From: ppolato <82828243+ppolato@users.noreply.github.com> Date: Wed, 29 Apr 2026 18:20:40 +0200 Subject: [PATCH] SERVER-121274 Add test coverage for the change stream control events generated by movePrimary (#52826) Co-authored-by: Copilot GitOrigin-RevId: 73b0541111bdf4161590383c3eacdd2f7352dcaa --- ..._generate_historical_placement_metadata.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/jstests/noPassthrough/ddl/ddl_commits_generate_historical_placement_metadata.js b/jstests/noPassthrough/ddl/ddl_commits_generate_historical_placement_metadata.js index 2be7606cbfb..473ea5d886e 100644 --- a/jstests/noPassthrough/ddl/ddl_commits_generate_historical_placement_metadata.js +++ b/jstests/noPassthrough/ddl/ddl_commits_generate_historical_placement_metadata.js @@ -235,6 +235,15 @@ function makeMoveChunkEntryTemplate(nss, donor, recipient, noMoreChunksOnDonor) }; } +function makeMovePrimaryEntryTemplate(dbName, fromPrimary, toPrimary) { + return { + op: "n", + ns: dbName, + o: {msg: {movePrimary: dbName}}, + o2: {movePrimary: dbName, from: fromPrimary, to: toPrimary}, + }; +} + function makeChunkOnNewShardEntryTemplate(nss, donor, recipient) { return { op: "n", @@ -632,6 +641,22 @@ function testMovePrimary(dbName, fromPrimaryShardName, toPrimaryShardName) { // Verify that the new primary shard is the one specified in the command. const newDbInfo = getValidatedPlacementInfoForDB(dbName); assert.sameMembers(newDbInfo.shards, [toPrimaryShardName]); + + // Verify that the old primary shard a single op entry marking the DDL commit. + const expectedEntryTemplatesOnOldPrimary = [ + makeMovePrimaryEntryTemplate(dbName, fromPrimaryShardName, toPrimaryShardName), + ]; + + const [movePrimaryEntry] = verifyCommitOpEntriesOnShards(expectedEntryTemplatesOnOldPrimary, [ + fromPrimaryShardName, + ])[fromPrimaryShardName]; + + // The commit entry must not be hidden to change stream readers. + assert(!movePrimaryEntry.fromMigrate || movePrimaryEntry.fromMigrate === false); + + // The op entry represents a control event for change stream readers, + // so that it must be emitted after inserting the related placement change doc. + assert(timestampCmp(movePrimaryEntry.ts, newDbInfo.timestamp) > 0); } function testDropCollection() {