Skip to content

Commit 7259627

Browse files
test: ensure tmp directory cleanup in check-emfile-handling.js (#19036)
* test: ensure tmp directory cleanup in `check-emfile-handling.js` * increase `maxRetries` * increase `maxRetries` further * add delay * use `Promise.allSettled` to ensure all `readFile`s are settled
1 parent 50f03a1 commit 7259627

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

tools/check-emfile-handling.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ if (os.platform() !== "win32") {
5656
*/
5757
function generateFiles() {
5858

59+
fs.rmSync(OUTPUT_DIRECTORY, { recursive: true, force: true, maxRetries: 8 });
5960
fs.mkdirSync(OUTPUT_DIRECTORY, { recursive: true });
6061

6162
for (let i = 0; i < FILE_COUNT; i++) {
@@ -69,16 +70,21 @@ function generateFiles() {
6970

7071
/**
7172
* Generates an EMFILE error by reading all files in the output directory.
72-
* @returns {Promise<Buffer[]>} A promise that resolves with the contents of all files.
73+
* @returns {undefined}
7374
*/
74-
function generateEmFileError() {
75-
return Promise.all(
75+
async function generateEmFileError() {
76+
const results = await Promise.allSettled(
7677
Array.from({ length: FILE_COUNT }, (_, i) => {
7778
const fileName = `file_${i}.js`;
7879

7980
return readFile(`${OUTPUT_DIRECTORY}/${fileName}`);
8081
})
8182
);
83+
const failedResult = results.find(({ status }) => status === "rejected");
84+
85+
if (failedResult?.reason) {
86+
throw failedResult.reason;
87+
}
8288
}
8389

8490
//------------------------------------------------------------------------------
@@ -106,4 +112,7 @@ generateEmFileError()
106112
console.error("❌ Unexpected error encountered:", error.message);
107113
throw error;
108114
}
115+
})
116+
.finally(() => {
117+
fs.rmSync(OUTPUT_DIRECTORY, { recursive: true, force: true, maxRetries: 8 });
109118
});

0 commit comments

Comments
 (0)