diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..e29f5e504 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.travis.yml b/.travis.yml index 1b9165051..44c9ad55f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/lib/client/doc.js b/lib/client/doc.js index 05e17976d..88f4e0a71 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -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; } @@ -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); }); } }; diff --git a/test/client/subscribe.js b/test/client/subscribe.js index 567031d0a..9e1968466 100644 --- a/test/client/subscribe.js +++ b/test/client/subscribe.js @@ -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) {