From d26b0143910250fffae4b97f8ea376ede1ef4093 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 19 Jan 2016 23:30:43 -0800 Subject: test: refactor test-fs-watch * Exchange 20 millisecond timers for setImmediate(). * Do not attempt to unlink path that will have been guaranteed to be removed by `common.refreshTmpDir()` * Do not swallow errors thrown by failed creation of needed test subdirectory. If that happens, we want to know about it. * Use `common.isSunOS` in one place where it is applicable PR-URL: https://github.com/nodejs/node/pull/4776 Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas --- test/sequential/test-fs-watch.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/sequential/test-fs-watch.js b/test/sequential/test-fs-watch.js index 10f4baf591..51d737ddbe 100644 --- a/test/sequential/test-fs-watch.js +++ b/test/sequential/test-fs-watch.js @@ -51,9 +51,9 @@ assert.doesNotThrow( } ); -setTimeout(function() { +setImmediate(function() { fs.writeFileSync(filepathOne, 'world'); -}, 20); +}); process.chdir(testDir); @@ -74,17 +74,16 @@ assert.doesNotThrow( } ); -setTimeout(function() { +setImmediate(function() { fs.writeFileSync(filepathTwoAbs, 'pardner'); -}, 20); +}); -try { fs.unlinkSync(filepathThree); } catch (e) {} -try { fs.mkdirSync(testsubdir, 0o700); } catch (e) {} +fs.mkdirSync(testsubdir, 0o700); assert.doesNotThrow( function() { var watcher = fs.watch(testsubdir, function(event, filename) { - var renameEv = process.platform === 'sunos' ? 'change' : 'rename'; + var renameEv = common.isSunOS ? 'change' : 'rename'; assert.equal(renameEv, event); if (expectFilePath) { assert.equal('newfile.txt', filename); @@ -97,10 +96,10 @@ assert.doesNotThrow( } ); -setTimeout(function() { +setImmediate(function() { var fd = fs.openSync(filepathThree, 'w'); fs.closeSync(fd); -}, 20); +}); // https://github.com/joyent/node/issues/2293 - non-persistent watcher should // not block the event loop -- cgit v1.2.1