From bbb42ef088566f229d2b10b805da90154855a722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Reis?= Date: Fri, 2 Aug 2019 15:15:15 +0100 Subject: [PATCH] fixup! test: clean tmpdir on process exit Detect and error when open files are left behind in Linux. --- test/common/tmpdir.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/common/tmpdir.js b/test/common/tmpdir.js index c66756e21b47f2..04545d6763f310 100644 --- a/test/common/tmpdir.js +++ b/test/common/tmpdir.js @@ -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 = {