summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/queryStats/query_stats_upgrade.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthrough/queryStats/query_stats_upgrade.js')
-rw-r--r--jstests/noPassthrough/queryStats/query_stats_upgrade.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/jstests/noPassthrough/queryStats/query_stats_upgrade.js b/jstests/noPassthrough/queryStats/query_stats_upgrade.js
new file mode 100644
index 00000000000..de23b157e99
--- /dev/null
+++ b/jstests/noPassthrough/queryStats/query_stats_upgrade.js
@@ -0,0 +1,45 @@
+/**
+ * Test that query stats doesn't work on a lower FCV version but works after an FCV upgrade.
+ * @tags: [
+ * requires_fcv_60,
+ * # Re-uses FCV state in the dbpath.
+ * requires_persistence
+ * ]
+ */
+load('jstests/libs/analyze_plan.js');
+load("jstests/libs/feature_flag_util.js");
+
+(function() {
+"use strict";
+
+const dbpath = MongoRunner.dataPath + jsTestName();
+let conn = MongoRunner.runMongod({dbpath: dbpath});
+let testDB = conn.getDB(jsTestName());
+
+function testLower(restart = false) {
+ let adminDB = conn.getDB("admin");
+ assert.commandWorked(
+ adminDB.runCommand({setFeatureCompatibilityVersion: binVersionToFCV("last-lts")}));
+ if (restart) {
+ MongoRunner.stopMongod(conn);
+ conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
+ testDB = conn.getDB(jsTestName());
+ adminDB = conn.getDB("admin");
+ }
+
+ assert.commandFailedWithCode(
+ testDB.adminCommand({aggregate: 1, pipeline: [{$queryStats: {}}], cursor: {}}),
+ ErrorCodes.QueryFeatureNotAllowed);
+
+ // Upgrade FCV.
+ assert.commandWorked(
+ adminDB.runCommand({setFeatureCompatibilityVersion: binVersionToFCV("latest")}));
+
+ // We should be able to run a query stats pipeline now that the FCV is correct.
+ assert.commandWorked(
+ testDB.adminCommand({aggregate: 1, pipeline: [{$queryStats: {}}], cursor: {}}));
+}
+testLower(true);
+testLower(false);
+MongoRunner.stopMongod(conn);
+})(); \ No newline at end of file