0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-21 20:49:10 +01:00

SERVER-73541 Use dynamic import when loading parallel tester tests

This commit is contained in:
Matt Broadstone 2023-02-03 13:59:23 +00:00 committed by Evergreen Agent
parent 64cdb91c0f
commit ee66aa703f
4 changed files with 20 additions and 14 deletions

View File

@ -1,9 +1,9 @@
env: env:
es2020: true es2022: true
mongo: true mongo: true
parserOptions: parserOptions:
ecmaVersion: 2020 ecmaVersion: 2022
sourceType: "module" sourceType: "module"
rules: rules:

View File

@ -124,8 +124,8 @@ if (typeof _threadInject != "undefined") {
this.params.push(args); this.params.push(args);
}; };
ParallelTester.prototype.run = function(msg) { ParallelTester.prototype.run = async function(msg) {
assert.parallelTests(this.params, msg); await assert.parallelTests(this.params, msg);
}; };
// creates lists of tests from jstests dir in a format suitable for use by // creates lists of tests from jstests dir in a format suitable for use by
@ -359,22 +359,28 @@ if (typeof _threadInject != "undefined") {
return params; 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 // runs a set of test files
// first argument is an identifier for this tester, remaining arguments are file names // 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 args = Array.from(arguments);
var suite = args.shift(); var suite = args.shift();
args.forEach(function(x) { for (const x of args) {
print(" S" + suite + " Test : " + x + " ..."); 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 // Create a new connection to the db for each file. If tests share the same
// connection it can create difficult to debug issues. // connection it can create difficult to debug issues.
db = new Mongo(db.getMongo().host).getDB(db.getName()); db = new Mongo(db.getMongo().host).getDB(db.getName());
gc(); gc();
load(x); await import(x);
}, 1); });
print(" S" + suite + " Test : " + x + " " + time + "ms"); print(" S" + suite + " Test : " + x + " " + time + "ms");
}); }
}; };
// params: array of arrays, each element of which consists of a function followed // params: array of arrays, each element of which consists of a function followed

View File

@ -6,12 +6,12 @@ Random.setRandomSeed();
var params = ParallelTester.createJstestsLists(4); var params = ParallelTester.createJstestsLists(4);
var t = new ParallelTester(); var t = new ParallelTester();
for (i in params) { for (let i in params) {
t.add(ParallelTester.fileTester, params[i]); t.add(ParallelTester.fileTester, params[i]);
} }
try { try {
t.run("one or more tests failed"); await t.run("one or more tests failed");
} finally { } finally {
print( print(
"If the failure here is due to a test unexpected being run, " + "If the failure here is due to a test unexpected being run, " +

View File

@ -8,7 +8,7 @@ Random.setRandomSeed();
var params = ParallelTester.createJstestsLists(4); var params = ParallelTester.createJstestsLists(4);
var t = new ParallelTester(); var t = new ParallelTester();
for (i in params) { for (let i in params) {
t.add(ParallelTester.fileTester, params[i]); t.add(ParallelTester.fileTester, params[i]);
} }
@ -28,7 +28,7 @@ for (var i = 4; i < 8; ++i) {
t.add(EventGenerator.dispatch, g.getEvents()); t.add(EventGenerator.dispatch, g.getEvents());
} }
try { try {
t.run("one or more tests failed"); await t.run("one or more tests failed");
} finally { } finally {
print( print(
"If the failure here is due to a test unexpected being run, " + "If the failure here is due to a test unexpected being run, " +