Files
mongo/jstests/core/shell/benchrun_pipeline_updates.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

58 lines
1.8 KiB
JavaScript

/**
* Tests that benchRun can understand pipeline-style updates and findAndModifys.
*
* @tags: [
* uses_multiple_connections,
* # benchRun does not use runCommand which is required by the `simulate_atlas_proxy` override.
* simulate_atlas_proxy_incompatible,
* # TODO SERVER-84638: remove this incompatibility once benchrun passes on shell options.
* grpc_incompatible,
* ]
*/
const coll = db.benchrun_pipeline_updates;
coll.drop();
assert.commandWorked(coll.insert({_id: 0, x: 0}));
// Test that a basic pipeline can be used by an update op.
let benchArgs = {
ops: [
{
op: "update",
ns: coll.getFullName(),
query: {_id: 0},
writeCmd: true,
update: [{$set: {x: {$add: ["$x", 1]}}}],
},
],
parallel: 2,
seconds: 1,
host: db.getMongo().host,
};
if (jsTest.options().auth) {
benchArgs["db"] = "admin";
benchArgs["username"] = jsTest.options().authUser;
benchArgs["password"] = jsTest.options().authPassword;
}
let res = benchRun(benchArgs);
assert.eq(res.errCount, 0);
assert.gte(coll.findOne({_id: 0}).x, 2, "Expected at least one update to succeed and increment 'x'");
// Now test that the pipeline is still subject to benchRun's keyword replacement.
// Initialize x to something outside the range we'll expect it to be in below if the updates
// succeed.
assert.commandWorked(coll.updateOne({_id: 0}, {$set: {x: 100}}));
benchArgs.ops = [
{
op: "update",
ns: coll.getFullName(),
query: {_id: 0},
writeCmd: true,
update: [{$project: {x: {$literal: {"#RAND_INT_PLUS_THREAD": [0, 2]}}}}],
},
];
res = benchRun(benchArgs);
assert.eq(res.errCount, 0);
assert.lte(coll.findOne({_id: 0}).x, 3, "Expected 'x' to be no more than 3 after randInt replacement");