Skip to content

Commit

Permalink
fixup! test: clean tmpdir on process exit
Browse files Browse the repository at this point in the history
Detect and error when open files are left behind in Linux.
  • Loading branch information
joaocgreis committed Aug 2, 2019
1 parent 2367954 commit bbb42ef
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/common/tmpdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,34 @@ function onexit() {
console.error();
throw e;
}

openFilesCheck();
}

function openFilesCheck() {
const cmd = `lsof -p ${process.pid}`;

if (process.platform !== 'linux')
return;

let openFiles;
try {
openFiles = execSync(cmd, { encoding: 'utf8' });
} catch {
// Ignore errors
return;
}

const openFilesLines = openFiles.trim().split(/\r?\n/);
const tmpFiles =
openFilesLines.filter((l) => (l.indexOf(`${tmpdirName}/`) !== -1));

if (tmpFiles.length > 0) {
console.error('Open files in tmpPath:');
console.error(openFilesLines[0]); // header
console.error(tmpFiles.join('\n'));
throw new Error('Open files found in tmpPath');
}
}

module.exports = {
Expand Down

0 comments on commit bbb42ef

Please sign in to comment.