Repository navigation
test: fix flaky test-fs-watch-encoding on OS X #7356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
squash: fixes for SmartOS and OS X
- Loading branch information
commit a05df90af3a0158dfb67277f07c56efc9b7693ab
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,18 @@ | ||
| 'use strict'; | ||
|
|
||
| // This test is a bit more complicated than it ideally needs to be to work | ||
| // around issues on OS X and SmartOS. | ||
| // | ||
| // On OS X, watch events are subject to peculiar timing oddities such that an | ||
| // event might fire our of order. The synchronous refreshing of the tmp | ||
| // directory might trigger an event on the watchers that are instantiated after | ||
| // it! | ||
| // | ||
| // On SmartOS, the watch events fire but the filename is null. | ||
|
|
||
| const common = require('../common'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const assert = require('assert'); | ||
|
|
||
| if (common.isFreeBSD) { | ||
| common.skip('Test currently not working on FreeBSD'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this. The test now passes in |
||
|
|
@@ -33,18 +42,17 @@ const watcher1 = fs.watch( | |
| common.tmpDir, | ||
| {encoding: 'hex'}, | ||
| (event, filename) => { | ||
| console.log(event); | ||
| assert.equal(filename, 'e696b0e5bbbae69687e5a4b9e4bbb62e747874'); | ||
| unregisterWatcher(watcher1); | ||
| if (['e696b0e5bbbae69687e5a4b9e4bbb62e747874', null].includes(filename)) | ||
| done(watcher1); | ||
| } | ||
| ); | ||
| registerWatcher(watcher1); | ||
|
|
||
| const watcher2 = fs.watch( | ||
| common.tmpDir, | ||
| (event, filename) => { | ||
| assert.equal(filename, fn); | ||
| unregisterWatcher(watcher2); | ||
| if ([fn, null].includes(filename)) | ||
| done(watcher2); | ||
| } | ||
| ); | ||
| registerWatcher(watcher2); | ||
|
|
@@ -53,13 +61,16 @@ const watcher3 = fs.watch( | |
| common.tmpDir, | ||
| {encoding: 'buffer'}, | ||
| (event, filename) => { | ||
| assert(filename instanceof Buffer); | ||
| assert.equal(filename.toString('utf8'), fn); | ||
| unregisterWatcher(watcher3); | ||
| if (filename instanceof Buffer && filename.toString('utf8') === fn) | ||
| done(watcher3); | ||
| else if (filename === null) | ||
| done(watcher3); | ||
| } | ||
| ); | ||
| registerWatcher(watcher3); | ||
|
|
||
| const done = common.mustCall(unregisterWatcher, watchers.size); | ||
|
|
||
| // OS X and perhaps other systems can have surprising race conditions with | ||
| // file events. So repeat the operation in case it is missed the first time. | ||
| const interval = setInterval(() => { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/our/out/