fix(watcher.node): Defer events during initial scan, track full event sequences, and harden watcher shutdown
This commit is contained in:
@@ -60,8 +60,12 @@ tap.test('should detect delete+recreate (inode change scenario)', async () => {
|
||||
const initialInode = initialStats.ino;
|
||||
console.log(`[test] Initial inode: ${initialInode}`);
|
||||
|
||||
const changeObservable = await testSmartwatch.getObservableFor('change');
|
||||
const eventPromise = waitForEvent(changeObservable, 3000);
|
||||
// With event sequence tracking, delete+recreate emits: unlink, then add
|
||||
// This is more accurate than just emitting 'change'
|
||||
const unlinkObservable = await testSmartwatch.getObservableFor('unlink');
|
||||
const addObservable = await testSmartwatch.getObservableFor('add');
|
||||
const unlinkPromise = waitForEvent(unlinkObservable, 3000);
|
||||
const addPromise = waitForEvent(addObservable, 3000);
|
||||
|
||||
// Delete and recreate (this creates a new inode)
|
||||
await fs.promises.unlink(testFile);
|
||||
@@ -73,9 +77,11 @@ tap.test('should detect delete+recreate (inode change scenario)', async () => {
|
||||
console.log(`[test] New inode: ${newInode}`);
|
||||
expect(newInode).not.toEqual(initialInode);
|
||||
|
||||
// Should still detect the change
|
||||
const [filePath] = await eventPromise;
|
||||
expect(filePath).toInclude('inode-test.txt');
|
||||
// Should detect both unlink and add events for delete+recreate
|
||||
const [[unlinkPath], [addPath]] = await Promise.all([unlinkPromise, addPromise]);
|
||||
expect(unlinkPath).toInclude('inode-test.txt');
|
||||
expect(addPath).toInclude('inode-test.txt');
|
||||
console.log(`[test] Detected unlink + add events for delete+recreate`);
|
||||
|
||||
// Cleanup
|
||||
await fs.promises.unlink(testFile);
|
||||
|
||||
Reference in New Issue
Block a user