Skip to content
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

Emit error on failed resubscribe #174

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = LF
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: node_js
node_js:
- 6
- 5
- 4
- 0.10
- "6"
- "8"
- "10"
script: "npm run jshint && npm run test-cover"
# Send coverage data to Coveralls
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
7 changes: 5 additions & 2 deletions lib/client/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,15 @@ Doc.prototype._onConnectionStateChanged = function() {
};

Doc.prototype._resubscribe = function() {
var doc = this;
var callbacks = this.pendingFetch;
this.pendingFetch = [];

if (this.wantSubscribe) {
if (callbacks.length) {
this.subscribe(function(err) {
callEach(callbacks, err);
var called = callEach(callbacks, err);
if (err && !called) doc.emit('error', err);
});
return;
}
Expand All @@ -364,7 +366,8 @@ Doc.prototype._resubscribe = function() {

if (callbacks.length) {
this.fetch(function(err) {
callEach(callbacks, err);
var called = callEach(callbacks, err);
if (err && !called) doc.emit('error', err);
});
}
};
Expand Down
23 changes: 23 additions & 0 deletions test/client/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,29 @@ describe('client subscribe', function() {
});
});

it(method + ' emits error passed to doc read middleware after reconnect', function(done) {
this.backend.use('doc', function(request, next) {
next({message: 'Reject doc read'});
});
var backend = this.backend;
var doc = this.backend.connect().get('dogs', 'fido');
var doc2 = this.backend.connect().get('dogs', 'fido');
doc.create({age: 3}, function(err) {
if (err) return done(err);
doc2[method]();
doc2.on('error', function(err) {
expect(err.message).equal('Reject doc read');
expect(doc2.version).eql(null);
expect(doc2.data).eql(undefined);
done();
});
doc2.connection.close();
process.nextTick(function() {
backend.connect(doc2.connection);
});
});
});

it(method + ' will call back when ops are pending', function(done) {
var doc = this.backend.connect().get('dogs', 'fido');
doc.create({age: 3}, function(err) {
Expand Down