Skip to content

Commit bbb42ef

Browse files
committed
fixup! test: clean tmpdir on process exit
Detect and error when open files are left behind in Linux.
1 parent 2367954 commit bbb42ef

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/common/tmpdir.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,34 @@ function onexit() {
135135
console.error();
136136
throw e;
137137
}
138+
139+
openFilesCheck();
140+
}
141+
142+
function openFilesCheck() {
143+
const cmd = `lsof -p ${process.pid}`;
144+
145+
if (process.platform !== 'linux')
146+
return;
147+
148+
let openFiles;
149+
try {
150+
openFiles = execSync(cmd, { encoding: 'utf8' });
151+
} catch {
152+
// Ignore errors
153+
return;
154+
}
155+
156+
const openFilesLines = openFiles.trim().split(/\r?\n/);
157+
const tmpFiles =
158+
openFilesLines.filter((l) => (l.indexOf(`${tmpdirName}/`) !== -1));
159+
160+
if (tmpFiles.length > 0) {
161+
console.error('Open files in tmpPath:');
162+
console.error(openFilesLines[0]); // header
163+
console.error(tmpFiles.join('\n'));
164+
throw new Error('Open files found in tmpPath');
165+
}
138166
}
139167

140168
module.exports = {

0 commit comments

Comments
 (0)