From 8036f3e625b4c99396a499db1ae4d95a8c78fc69 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 11 Jul 2018 20:04:28 -0700 Subject: [PATCH 1/2] test: fix flaky watchFile() The regression that test-fs-watch-file-enoent-after-deletion was written to test for involves whether or not the callback runs or not. Checking what the file watcher reports unfortunately is subject to race conditions on Windows (and possibly elsewhere) because the file watcher returns control to the event loop before it may be receiving data from the OS. So remove those assertions. The test still checks what it is supposed to check, but is no longer subject to race conditions. --- .../test-fs-watch-file-enoent-after-deletion.js | 3 --- 1 file changed, 3 deletions(-) rename test/{sequential => parallel}/test-fs-watch-file-enoent-after-deletion.js (94%) diff --git a/test/sequential/test-fs-watch-file-enoent-after-deletion.js b/test/parallel/test-fs-watch-file-enoent-after-deletion.js similarity index 94% rename from test/sequential/test-fs-watch-file-enoent-after-deletion.js rename to test/parallel/test-fs-watch-file-enoent-after-deletion.js index f5b9012acabe58..83c7516c9c6ca9 100644 --- a/test/sequential/test-fs-watch-file-enoent-after-deletion.js +++ b/test/parallel/test-fs-watch-file-enoent-after-deletion.js @@ -32,7 +32,6 @@ const common = require('../common'); // stopped it from getting emitted. // https://github.com/nodejs/node-v0.x-archive/issues/4027 -const assert = require('assert'); const path = require('path'); const fs = require('fs'); @@ -43,8 +42,6 @@ const filename = path.join(tmpdir.path, 'watched'); fs.writeFileSync(filename, 'quis custodiet ipsos custodes'); fs.watchFile(filename, { interval: 50 }, common.mustCall(function(curr, prev) { - assert.strictEqual(prev.nlink, 1); - assert.strictEqual(curr.nlink, 0); fs.unwatchFile(filename); })); From c991abcd31896645c701d0173ca08f1be960f2d3 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 12 Jul 2018 19:47:52 -0700 Subject: [PATCH 2/2] test: remove timer in fs.watchFile() test The timer was there to address a race condition that has been removed from the test. Remove it. --- test/parallel/test-fs-watch-file-enoent-after-deletion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-fs-watch-file-enoent-after-deletion.js b/test/parallel/test-fs-watch-file-enoent-after-deletion.js index 83c7516c9c6ca9..6eaa4c68c58bc8 100644 --- a/test/parallel/test-fs-watch-file-enoent-after-deletion.js +++ b/test/parallel/test-fs-watch-file-enoent-after-deletion.js @@ -45,4 +45,4 @@ fs.watchFile(filename, { interval: 50 }, common.mustCall(function(curr, prev) { fs.unwatchFile(filename); })); -setTimeout(fs.unlinkSync, common.platformTimeout(300), filename); +fs.unlinkSync(filename);