SERVER-109892 Update expected error codes for multiversion rank fusion tests (#40662)

GitOrigin-RevId: 96154a0bc1183a20eff98525bbbc8edf7d337c6a
This commit is contained in:
Alyssa Clark 2025-08-29 09:58:10 -04:00 committed by MongoDB Bot
parent faf12e9eae
commit de9fef5886
2 changed files with 66 additions and 54 deletions

View File

@ -10,8 +10,6 @@
* ]
*/
import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js";
const testDb = db.getSiblingDB(jsTestName());
const collName = "api_version_pipeline_stages";
const coll = testDb[collName];
@ -30,41 +28,24 @@ const unstablePipelines = [
[{$unionWith: {coll: "coll2", pipeline: [{$collStats: {latencyStats: {}}}]}}],
[{$lookup: {from: "coll2", pipeline: [{$indexStats: {}}]}}],
[{$facet: {field1: [], field2: [{$indexStats: {}}]}}],
];
function is81orAbove(db) {
const res = db.getSiblingDB("admin")
.system.version.find({_id: "featureCompatibilityVersion"})
.toArray();
return res.length == 0 || MongoRunner.compareBinVersions(res[0].version, "8.1") >= 0;
}
// TODO (SERVER-98651) listClusterCatalog can always be included once backported.
if (is81orAbove(db)) {
unstablePipelines.push([{$listClusterCatalog: {}}]);
}
// TODO SERVER-98591 Change RankFusionFull to RankFusionBasic.
unstablePipelines.push([{$rankFusion: {input: {pipelines: {field1: [{$sort: {foo: 1}}]}}}}]);
let hybridSearchPipelines = [
// $score is not included in the strict api.
[{$rankFusion: {input: {pipelines: {field1: [{$sort: {foo: 1}}]}}}}],
[{$score: {score: 10}}],
// $minMaxScaler is not included in the strict api.
[{
$setWindowFields: {
sortBy: {_id: 1},
output: {
"relativeXValue": {
$minMaxScaler: {
input: "$x",
[
{
$setWindowFields: {
sortBy: {_id: 1},
output: {
"relativeXValue": {
$minMaxScaler: {
input: "$x",
},
window: {range: ["unbounded", "unbounded"]},
},
window: {range: ["unbounded", "unbounded"]}
},
}
}
}],
// $scoreFusion is not included in the strict api.
},
},
],
[{
$scoreFusion: {
input: {
@ -84,17 +65,37 @@ let hybridSearchPipelines = [
}]
];
unstablePipelines.concat(hybridSearchPipelines);
function is81orAbove(db) {
const res = db.getSiblingDB("admin")
.system.version.find({_id: "featureCompatibilityVersion"})
.toArray();
return res.length == 0 || MongoRunner.compareBinVersions(res[0].version, "8.1") >= 0;
}
// TODO (SERVER-98651) listClusterCatalog can always be included once backported.
if (is81orAbove(db)) {
unstablePipelines.push([{$listClusterCatalog: {}}]);
}
function assertAggregateFailsWithAPIStrict(pipeline) {
assert.commandFailedWithCode(testDb.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: true,
apiVersion: "1"
}),
[ErrorCodes.APIStrictError, kUnrecognizedPipelineStageErrorCode]);
// The error code may also be an unrecognized pipeline stage, QueryFeatureNotAllowed, or parsing
// error, if the test is running in a multiversioned scenario where the stage does not exist or
// is not enabled on the older version.
assert.commandFailedWithCode(
testDb.runCommand({
aggregate: collName,
pipeline: pipeline,
cursor: {},
apiStrict: true,
apiVersion: "1",
}),
[
ErrorCodes.APIStrictError,
kUnrecognizedPipelineStageErrorCode,
ErrorCodes.QueryFeatureNotAllowed,
ErrorCodes.FailedToParse,
],
);
}
for (let pipeline of unstablePipelines) {
@ -102,16 +103,24 @@ for (let pipeline of unstablePipelines) {
assertAggregateFailsWithAPIStrict(pipeline);
// Assert error thrown when creating a view on a pipeline with stages not in API Version 1.
// The error code may also be an unrecognized pipeline stage, if the test is running in a
// multiversioned scenario.
assert.commandFailedWithCode(testDb.runCommand({
create: 'api_version_pipeline_stages_should_fail',
viewOn: collName,
pipeline: pipeline,
apiStrict: true,
apiVersion: "1"
}),
[ErrorCodes.APIStrictError, kUnrecognizedPipelineStageErrorCode]);
// The error code may also be an unrecognized pipeline stage, QueryFeatureNotAllowed, or parsing
// error, if the test is running in a multiversioned scenario where the stage does not exist or
// is not enabled on the older version.
assert.commandFailedWithCode(
testDb.runCommand({
create: "api_version_pipeline_stages_should_fail",
viewOn: collName,
pipeline: pipeline,
apiStrict: true,
apiVersion: "1",
}),
[
ErrorCodes.APIStrictError,
kUnrecognizedPipelineStageErrorCode,
ErrorCodes.QueryFeatureNotAllowed,
ErrorCodes.FailedToParse,
],
);
}
// Test that $collStats is allowed in APIVersion 1, even with 'apiStrict: true', so long as the only

View File

@ -67,8 +67,11 @@ function assertRankFusionCompletelyRejected(primaryConn) {
// Running $rankFusion against a view is rejected.
assert.commandWorked(db.createView(viewName, collName, viewPipeline));
assert.commandFailedWithCode(
db.runCommand({aggregate: viewName, pipeline: rankFusionPipeline, cursor: {}}),
[kUnrecognizedPipelineStageErrorCode, ErrorCodes.OptionNotSupportedOnView]);
db.runCommand({aggregate: viewName, pipeline: rankFusionPipeline, cursor: {}}), [
kUnrecognizedPipelineStageErrorCode,
ErrorCodes.QueryFeatureNotAllowed,
ErrorCodes.OptionNotSupportedOnView,
]);
}
function assertRankFusionCompletelyAccepted(primaryConn) {