diff --git a/.eslintrc.yml b/.eslintrc.yml index 575cde0bef7..3c52ea9aa42 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,9 +1,9 @@ env: - es2020: true + es2022: true mongo: true parserOptions: - ecmaVersion: 2020 + ecmaVersion: 2022 sourceType: "module" rules: diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js index 58f56109053..bff2dc5fb43 100644 --- a/jstests/libs/parallelTester.js +++ b/jstests/libs/parallelTester.js @@ -124,8 +124,8 @@ if (typeof _threadInject != "undefined") { this.params.push(args); }; - ParallelTester.prototype.run = function(msg) { - assert.parallelTests(this.params, msg); + ParallelTester.prototype.run = async function(msg) { + await assert.parallelTests(this.params, msg); }; // creates lists of tests from jstests dir in a format suitable for use by @@ -359,22 +359,28 @@ if (typeof _threadInject != "undefined") { return params; }; + async function measureAsync(fn) { + const start = new Date(); + await fn.apply(null, Array.from(arguments).slice(2)); + return (new Date()).getTime() - start.getTime(); + } + // runs a set of test files // first argument is an identifier for this tester, remaining arguments are file names - ParallelTester.fileTester = function() { + ParallelTester.fileTester = async function() { var args = Array.from(arguments); var suite = args.shift(); - args.forEach(function(x) { + for (const x of args) { print(" S" + suite + " Test : " + x + " ..."); - var time = Date.timeFunc(function() { + const time = await measureAsync(async function() { // Create a new connection to the db for each file. If tests share the same // connection it can create difficult to debug issues. db = new Mongo(db.getMongo().host).getDB(db.getName()); gc(); - load(x); - }, 1); + await import(x); + }); print(" S" + suite + " Test : " + x + " " + time + "ms"); - }); + } }; // params: array of arrays, each element of which consists of a function followed diff --git a/jstests/parallel/basic.js b/jstests/parallel/basic.js index 6ac6361991d..8e7e7ea8a1a 100644 --- a/jstests/parallel/basic.js +++ b/jstests/parallel/basic.js @@ -6,12 +6,12 @@ Random.setRandomSeed(); var params = ParallelTester.createJstestsLists(4); var t = new ParallelTester(); -for (i in params) { +for (let i in params) { t.add(ParallelTester.fileTester, params[i]); } try { - t.run("one or more tests failed"); + await t.run("one or more tests failed"); } finally { print( "If the failure here is due to a test unexpected being run, " + diff --git a/jstests/parallel/basicPlus.js b/jstests/parallel/basicPlus.js index bd5e4f4c085..eea5041dc3c 100644 --- a/jstests/parallel/basicPlus.js +++ b/jstests/parallel/basicPlus.js @@ -8,7 +8,7 @@ Random.setRandomSeed(); var params = ParallelTester.createJstestsLists(4); var t = new ParallelTester(); -for (i in params) { +for (let i in params) { t.add(ParallelTester.fileTester, params[i]); } @@ -28,7 +28,7 @@ for (var i = 4; i < 8; ++i) { t.add(EventGenerator.dispatch, g.getEvents()); } try { - t.run("one or more tests failed"); + await t.run("one or more tests failed"); } finally { print( "If the failure here is due to a test unexpected being run, " +