Skip to content

Commit

Permalink
test: make fs watch test more stable
Browse files Browse the repository at this point in the history
PR-URL: #41715
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
benjamingr authored and ruyadorno committed Feb 7, 2022
1 parent e6a1896 commit 5f1a59c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions test/pummel/test-fs-watch-non-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (common.isIBMi) {

const path = require('path');
const fs = require('fs');

const assert = require('assert');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

Expand All @@ -38,13 +38,14 @@ const filepath = path.join(testsubdir, 'watch.txt');

fs.mkdirSync(testsubdir, 0o700);

// Need a grace period, else the mkdirSync() above fires off an event.
setTimeout(function() {
const watcher = fs.watch(testDir, { persistent: true }, common.mustNotCall());
setTimeout(function() {
fs.writeFileSync(filepath, 'test');
}, 100);
setTimeout(function() {
watcher.close();
}, 500);
}, 50);
const watcher = fs.watch(testDir, { persistent: true }, (event, filename) => {
// This function may be called with the directory depending on timing but
// must not be called with the file..
assert.strictEqual(filename, 'testsubdir');
});
setTimeout(() => {
fs.writeFileSync(filepath, 'test');
}, 100);
setTimeout(() => {
watcher.close();
}, 500);

0 comments on commit 5f1a59c

Please sign in to comment.