|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | const common = require('../common');
|
| 4 | +const { setTimeout } = require('timers/promises'); |
4 | 5 |
|
5 | 6 |
|
6 | 7 | const assert = require('assert');
|
@@ -52,3 +53,29 @@ if (common.isOSX) {
|
52 | 53 | process.on('exit', function() {
|
53 | 54 | assert(watcherClosed, 'watcher Object was not closed');
|
54 | 55 | });
|
| 56 | + |
| 57 | +(async () => { |
| 58 | + // Assert recursive watch does not leak handles |
| 59 | + const rootDirectory = fs.mkdtempSync(testDir + path.sep); |
| 60 | + const testDirectory = path.join(rootDirectory, 'test-7'); |
| 61 | + const filePath = path.join(testDirectory, 'only-file.txt'); |
| 62 | + fs.mkdirSync(testDirectory); |
| 63 | + |
| 64 | + let watcherClosed = false; |
| 65 | + const watcher = fs.watch(testDirectory, { recursive: true }); |
| 66 | + watcher.on('change', common.mustCallAtLeast(async (event, filename) => { |
| 67 | + await setTimeout(common.platformTimeout(100)); |
| 68 | + if (filename === path.basename(filePath)) { |
| 69 | + watcher.close(); |
| 70 | + watcherClosed = true; |
| 71 | + } |
| 72 | + await setTimeout(common.platformTimeout(100)); |
| 73 | + assert(!process._getActiveHandles().some((handle) => handle.constructor.name === 'StatWatcher')); |
| 74 | + })); |
| 75 | + |
| 76 | + process.on('exit', function() { |
| 77 | + assert(watcherClosed, 'watcher Object was not closed'); |
| 78 | + }); |
| 79 | + await setTimeout(common.platformTimeout(100)); |
| 80 | + fs.writeFileSync(filePath, 'content'); |
| 81 | +})().then(common.mustCall()); |
0 commit comments