mongo-in-memory
mongo-in-memory copied to clipboard
EBUSY: resource busy or locked when stop server in tests
EBUSY: resource busy or locked, unlink 'C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\mongo-in-memory\.data-iosi15q\mongod.lock'
at Object.fs.unlinkSync (fs.js:1066:18)
at rimrafSync (C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\rimraf\rimraf.js:305:17)
at C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\rimraf\rimraf.js:341:5
at Array.forEach (native)
at rmkidsSync (C:\Users\nk.dusdeu468\Documents\Repositorys\example\news\node_modules\rimraf\rimraf.js:340:26)
I run into the issue when I run multiple tests in serie. The data directories won't be deleted.
Having this one also; it's a big problem when using it with Wallaby.js. It created 1500 .data
directories within a day.
Not really a solution; but I'm using a custom stop method to cleanup sibling directories that's been left earlier. This to reduce the noise a bit.
const getDataDirs = root => fs.readdirSync(root)
.filter(f => fs.statSync(path.join(root, f)).isDirectory())
.filter(d => /.data-[a-z0-9]{7}/.test(d))
.map(d => path.join(root, d));
const tryDelete = dir => {
try { rimraf.sync(dir) }
catch (e) { }
};
async function stopMongo(server) {
try {
await server.stop();
}
catch (ex) {
if (ex.code !== 'EBUSY' || ex.syscall !== 'unlink') {
throw ex;
}
}
finally {
const root = server.databasePath.substr(0, server.databasePath.length - 13);
getDataDirs(root).forEach(tryDelete);
}
}