diff --git a/.eslintrc.yml b/.eslintrc.yml index 80bd7f83037..d5312a02603 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -17,6 +17,14 @@ rules: no-redeclare: 0 no-constant-condition: 0 no-loss-of-precision: 0 + no-restricted-syntax: [ + 'error', + { + message: "Invalid load call. Please convert your library to a module and import it instead.", + selector: + 'CallExpression > Identifier[name="load"]' + } + ] globals: TestData: true diff --git a/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharded_collections_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharded_collections_jscore_passthrough.yml index f40e30e00e5..dc5840f072c 100644 --- a/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharded_collections_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharded_collections_jscore_passthrough.yml @@ -180,8 +180,8 @@ executor: config: shell_options: eval: >- - load("jstests/libs/override_methods/retry_aborted_db_and_index_creation.js"); - load("jstests/libs/override_methods/implicitly_shard_accessed_collections.js"); + await import("jstests/libs/override_methods/retry_aborted_db_and_index_creation.js"); + await import("jstests/libs/override_methods/implicitly_shard_accessed_collections.js"); hooks: - class: CheckReplDBHash - class: CheckMetadataConsistencyInBackground diff --git a/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharding_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharding_jscore_passthrough.yml index e0e921bdb70..d998631c736 100644 --- a/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharding_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/fcv_upgrade_downgrade_sharding_jscore_passthrough.yml @@ -134,7 +134,7 @@ executor: config: shell_options: eval: >- - load("jstests/libs/override_methods/retry_aborted_db_and_index_creation.js"); + await import("jstests/libs/override_methods/retry_aborted_db_and_index_creation.js"); hooks: - class: CheckReplDBHash - class: CheckMetadataConsistencyInBackground diff --git a/etc/system_perf.yml b/etc/system_perf.yml index 3f1b748fe4a..2bf81ee2580 100755 --- a/etc/system_perf.yml +++ b/etc/system_perf.yml @@ -405,7 +405,7 @@ functions: cat << EOF > mongodb/jstests/hooks/run_validate_collections.js print("NOTE: run_validate_collections.js will skip the oplog!"); TestData = { skipValidationNamespaces: ['local.oplog.rs'] }; - load('jstests/hooks/run_validate_collections.actual.js'); + await import("jstests/hooks/run_validate_collections.actual.js"); EOF fi tar czf mongodb${compile_variant|}.tar.gz mongodb diff --git a/jstests/core/query/number/numberlong.js b/jstests/core/query/number/numberlong.js index 5db5f199782..acb1823d459 100644 --- a/jstests/core/query/number/numberlong.js +++ b/jstests/core/query/number/numberlong.js @@ -204,7 +204,8 @@ var getCompletions = function(prefix) { return __autocomplete__; }; -var myNumberLong = new NumberLong(); +// assign `myNumberLong` to `globalThis` in case we are being run from another shell context. +globalThis.myNumberLong = new NumberLong(); var completions = getCompletions('myNumberLong.'); assert(completions.indexOf('myNumberLong.floatApprox') >= 0); assert(completions.indexOf('myNumberLong.top') >= 0); diff --git a/jstests/libs/txns/txn_passthrough_runner.js b/jstests/libs/txns/txn_passthrough_runner.js index bfe0e0103b7..4b2dc87681a 100644 --- a/jstests/libs/txns/txn_passthrough_runner.js +++ b/jstests/libs/txns/txn_passthrough_runner.js @@ -1,7 +1,7 @@ const testFile = TestData.multiStmtTxnTestFile; try { - load(testFile); + await import(testFile); } finally { // Run a lightweight command to allow the override file to commit the last command. // Ensure this command runs even if the test errors. diff --git a/jstests/noPassthrough/shell_load_file.js b/jstests/noPassthrough/shell_load_file.js index f7e55c815d8..38533586e5f 100644 --- a/jstests/noPassthrough/shell_load_file.js +++ b/jstests/noPassthrough/shell_load_file.js @@ -16,6 +16,7 @@ if (TestData.loadDepth >= 3) { } try { + /* eslint-disable-next-line no-restricted-syntax */ load("jstests/noPassthrough/shell_load_file.js"); } catch (e) { TestData.loadErrors.push(e); @@ -35,4 +36,4 @@ for (let i = 0; i < TestData.loadErrors.length; ++i) { /@jstests\\noPassthrough\\shell_load_file.js:/.test(error.stack), () => "JavaScript stacktrace from load() didn't include file paths (AKA stack frames): " + error.stack); -} \ No newline at end of file +} diff --git a/jstests/noPassthrough/shell_scoped_thread.js b/jstests/noPassthrough/shell_scoped_thread.js index bd4a85ef2eb..ce38247e56a 100644 --- a/jstests/noPassthrough/shell_scoped_thread.js +++ b/jstests/noPassthrough/shell_scoped_thread.js @@ -150,9 +150,11 @@ tests.push(function testUncaughtExceptionInNativeCode() { tests.push(function testUncaughtExceptionFromNestedThreads() { const thread = new Thread(function myFunction1() { + /* eslint-disable-next-line no-restricted-syntax */ load("jstests/libs/legacyThreadSupport.js"); const thread = new Thread(function myFunction2() { + /* eslint-disable-next-line no-restricted-syntax */ load("jstests/libs/legacyThreadSupport.js"); const thread = new Thread(function myFunction3() { diff --git a/jstests/sharding/fsync_deadlock.js b/jstests/sharding/fsync_deadlock.js index 66e1475a345..b5a6b57a21b 100644 --- a/jstests/sharding/fsync_deadlock.js +++ b/jstests/sharding/fsync_deadlock.js @@ -8,11 +8,7 @@ runs an fsyncLock which should fail and timeout as the global S lock cannot be t * ] */ import {configureFailPoint} from "jstests/libs/fail_point_util.js"; - -(function() { -'use strict'; - -load("jstests/libs/parallelTester.js"); +import {Thread} from "jstests/libs/parallelTester.js"; const st = new ShardingTest({ shards: 2, @@ -92,8 +88,5 @@ sleep(100); writeDecisionFp.off(); fsyncLockThread.join(); - txnThread.join(); - st.stop(); -})(); diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js index bd04a6724c3..7449819351a 100644 --- a/src/mongo/shell/replsettest.js +++ b/src/mongo/shell/replsettest.js @@ -104,6 +104,7 @@ var ReplSetTest = function ReplSetTest(opts) { } try { + /* eslint-disable-next-line no-restricted-syntax */ load("jstests/libs/legacyThreadSupport.js"); // For Thread. return true; } catch (e) { @@ -3440,7 +3441,6 @@ var ReplSetTest = function ReplSetTest(opts) { print("ReplSetTest stopSet skipping validation before stopping nodes."); } else if (parallelValidate) { print("ReplSetTest stopSet validating all replica set nodes before stopping them."); - print(` FOR PORTS: [${tojson(this.ports)}]`); this._validateNodes(this.ports); } diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js index 22aa2add630..dfe1fd8fe78 100644 --- a/src/mongo/shell/shardingtest.js +++ b/src/mongo/shell/shardingtest.js @@ -128,6 +128,7 @@ var ShardingTest = function ShardingTest(params) { } try { + /* eslint-disable-next-line no-restricted-syntax */ load("jstests/libs/legacyThreadSupport.js"); // For Thread. return true; } catch (e) {