-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stop polling if the poller has an error (#1936)
This will stop polling for FS events if there’s an error polling for fs events. Added tests for the JS. Tests for the c++ are harder. This supersedes #1804 and ensures no more events are fired if one reports an error. Fixes #1803 based upon @nfrasser's work.
- Loading branch information
Showing
4 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const Poller = require('./poller') | ||
|
||
class MockPollerBidnings { | ||
constructor(fd, callback) { | ||
this.fd = fd | ||
this.callback = callback | ||
} | ||
poll(flag) { | ||
this.lastPollFlag = flag | ||
setImmediate(() => this.callback(null, flag)) | ||
} | ||
} | ||
|
||
class ErrorPollerBindings { | ||
constructor(fd, callback) { | ||
this.fd = fd | ||
this.callback = callback | ||
} | ||
poll(flag) { | ||
this.lastPollFlag = flag | ||
setImmediate(() => this.callback(new Error('oh no!'), flag)) | ||
} | ||
} | ||
|
||
describe('Poller', () => { | ||
it('constructs', () => { | ||
new Poller(1, MockPollerBidnings) | ||
}) | ||
it('can listen to the readable event', done => { | ||
const poller = new Poller(1, MockPollerBidnings) | ||
poller.once('readable', err => { | ||
assert.equal(err, null) | ||
assert.equal(poller.poller.lastPollFlag, 1) | ||
done(err) | ||
}) | ||
}) | ||
it('can listen to the writable event', done => { | ||
const poller = new Poller(1, MockPollerBidnings) | ||
poller.once('writable', err => { | ||
assert.equal(err, null) | ||
assert.equal(poller.poller.lastPollFlag, 2) | ||
done(err) | ||
}) | ||
}) | ||
it('can listen to the disconnect event', done => { | ||
const poller = new Poller(1, MockPollerBidnings) | ||
poller.once('disconnect', err => { | ||
assert.equal(err, null) | ||
assert.equal(poller.poller.lastPollFlag, 4) | ||
done(err) | ||
}) | ||
}) | ||
it('reports errors on callback', done => { | ||
const poller = new Poller(1, ErrorPollerBindings) | ||
poller.once('readable', err => { | ||
assert.notEqual(err, null) | ||
done() | ||
}) | ||
}) | ||
}) |
This file contains 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
This file contains 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