diff --git a/test/common/tmpdir.js b/test/common/tmpdir.js index a71f5e95155ab8..ca82e7bca0e7b3 100644 --- a/test/common/tmpdir.js +++ b/test/common/tmpdir.js @@ -5,6 +5,7 @@ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); const { debuglog } = require('util'); +const { isMainThread } = require('worker_threads'); const debug = debuglog('test/tmpdir'); @@ -110,7 +111,8 @@ function refresh(opts = {}) { process.on('exit', () => { try { // Change dit to avoid possible EBUSY - process.chdir(testRoot); + if (isMainThread) + process.chdir(testRoot); rimrafSync(tmpPath, { spawn: false }); } catch (e) { console.error('Can\'t clean tmpdir:', tmpPath); diff --git a/test/parallel/test-fs-truncate-fd.js b/test/parallel/test-fs-truncate-fd.js index 057e4cb58df705..fbddbb32d5c0fc 100644 --- a/test/parallel/test-fs-truncate-fd.js +++ b/test/parallel/test-fs-truncate-fd.js @@ -21,7 +21,7 @@ fs.truncate(fd, 5, common.mustCall((err) => { assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello'); })); -process.on('beforeExit', () => { +process.once('beforeExit', () => { fs.closeSync(fd); fs.unlinkSync(filename); console.log('ok');