mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 03:31:35 +00:00

The recursive fs watch tests that mutate the watched folder immediately after fs.watch() returns are all flaking in the CI while the others that mutate the folder with a bit of delay aren't flaking. So this patch adds a bit of delay for the rest of the tests to deflake them. PR-URL: https://github.com/nodejs/node/pull/51842 Refs: https://github.com/nodejs/reliability/issues/790 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { watch, writeFileSync } = require('node:fs');
|
|
const { join } = require('node:path');
|
|
const tmpdir = require('../common/tmpdir.js');
|
|
const assert = require('assert');
|
|
|
|
if (common.isIBMi)
|
|
common.skip('IBMi does not support `fs.watch()`');
|
|
|
|
// fs-watch on folders have limited capability in AIX.
|
|
// The testcase makes use of folder watching, and causes
|
|
// hang. This behavior is documented. Skip this for AIX.
|
|
|
|
if (common.isAIX)
|
|
common.skip('folder watch capability is limited in AIX.');
|
|
|
|
tmpdir.refresh();
|
|
|
|
const tmpDir = tmpdir.path;
|
|
const filename = join(tmpDir, 'test.file');
|
|
|
|
const keepalive = setTimeout(() => {
|
|
throw new Error('timed out');
|
|
}, common.platformTimeout(30_000));
|
|
|
|
const watcher = watch(tmpDir, { recursive: true }, common.mustCall((eventType, _filename) => {
|
|
clearTimeout(keepalive);
|
|
watcher.close();
|
|
assert.strictEqual(eventType, 'rename');
|
|
assert.strictEqual(join(tmpDir, _filename), filename);
|
|
}));
|
|
|
|
// Do the write with a delay to ensure that the OS is ready to notify us.
|
|
setTimeout(() => {
|
|
writeFileSync(filename, 'foobar2');
|
|
}, common.platformTimeout(200));
|