Skip to content

Commit 767344e

Browse files
test: let one minify-corpora shard at a time merge the results
1 parent 4685e92 commit 767344e

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎eslint.config.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export default defineConfig([
316316
// inside the `describe` its export opens.
317317
files: ["test/specCases/minify-corpora.js"],
318318
rules: {
319+
"jest/consistent-test-it": "off",
319320
"jest/no-export": "off",
320321
"jest/require-top-level-describe": "off"
321322
}

‎test/specCases/minify-corpora.js‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,37 @@ const defineShard = (shard, count) => {
22022202
})
22032203
);
22042204
fs.renameSync(`${file}.tmp`, file);
2205+
// Shards finish moments apart, so one at a time reads, reports and cleans
2206+
// up; a holder that died frees the lock after a minute.
2207+
const lockDir = `${runDir}.lock`;
2208+
const pause = new Int32Array(new SharedArrayBuffer(4));
2209+
for (let waited = 0; ; waited += 10) {
2210+
try {
2211+
fs.mkdirSync(lockDir);
2212+
break;
2213+
} catch (err) {
2214+
if (/** @type {NodeJS.ErrnoException} */ (err).code !== "EEXIST") {
2215+
throw err;
2216+
}
2217+
if (waited >= 60000) break;
2218+
Atomics.wait(pause, 0, 0, 10);
2219+
}
2220+
}
2221+
try {
2222+
// The last shard already checked everything and removed the results.
2223+
if (!fs.existsSync(runDir)) return;
2224+
aggregate();
2225+
} finally {
2226+
fs.rmSync(lockDir, { recursive: true, force: true });
2227+
}
2228+
});
2229+
2230+
/**
2231+
* Merges every shard result present, rewrites the report from them, and once
2232+
* all shards ran every group, fails on the table entries none of them met.
2233+
* @returns {void}
2234+
*/
2235+
const aggregate = () => {
22052236
const done = fs
22062237
.readdirSync(runDir)
22072238
.filter((name) => name.endsWith(".json"));
@@ -2235,9 +2266,9 @@ const defineShard = (shard, count) => {
22352266
`List no difference the reference no longer makes:\n${stale.join("\n")}`
22362267
);
22372268
}
2238-
});
2269+
};
22392270

2240-
test("should run only the node_version ranges it can read", () => {
2271+
it("should run only the node_version ranges it can read", () => {
22412272
const major = Number(process.versions.node.split(".")[0]);
22422273
expect(nodeSatisfies(`>=${major}`)).toBe(true);
22432274
expect(nodeSatisfies(`>= ${major}`)).toBe(true);
@@ -2247,7 +2278,7 @@ const defineShard = (shard, count) => {
22472278
});
22482279

22492280
if (shard === 1 && isPresent(referenceDir)) {
2250-
test("should pin the reference's corpus to the version it is compared with", () => {
2281+
it("should pin the reference's corpus to the version it is compared with", () => {
22512282
const pinned = JSON.parse(
22522283
fs.readFileSync(path.join(referenceDir, "package.json"), "utf8")
22532284
).version;
@@ -2256,7 +2287,7 @@ const defineShard = (shard, count) => {
22562287
}
22572288

22582289
if (shard === 1 && isPresent(oxcTestsDir)) {
2259-
test("should pin oxc's corpus to the oxc-minify it is compared with", () => {
2290+
it("should pin oxc's corpus to the oxc-minify it is compared with", () => {
22602291
const pinned = JSON.parse(
22612292
fs.readFileSync(
22622293
path.join(externalDir, "oxc/napi/minify/package.json"),

0 commit comments

Comments
 (0)