From 3569a631f70bb16a38aebe297240308d5e81fb9b Mon Sep 17 00:00:00 2001 From: Greg Kubisa Date: Thu, 12 Jul 2018 13:30:32 +0200 Subject: [PATCH 1/3] Make whenNothingPending always async --- lib/client/doc.js | 9 ++++++++- test/client/doc.js | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/client/doc.js b/lib/client/doc.js index 05e17976d..66be2e166 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -200,7 +200,14 @@ Doc.prototype.whenNothingPending = function(callback) { this.once('nothing pending', callback); return; } - callback(); + var doc = this; + process.nextTick(function() { + if (doc.hasPending()) { + doc.once('nothing pending', callback); + return; + } + callback(); + }); }; Doc.prototype.hasPending = function() { diff --git a/test/client/doc.js b/test/client/doc.js index b44f52a2b..49078cb40 100644 --- a/test/client/doc.js +++ b/test/client/doc.js @@ -1,7 +1,7 @@ var Backend = require('../../lib/backend'); var expect = require('expect.js'); -describe('client query subscribe', function() { +describe('client doc subscribe', function() { beforeEach(function() { this.backend = new Backend(); @@ -14,28 +14,39 @@ describe('client query subscribe', function() { expect(doc).equal(doc2); }); - it('calling doc.destroy unregisters it', function() { - var doc = this.connection.get('dogs', 'fido'); - expect(this.connection.getExisting('dogs', 'fido')).equal(doc); + it('calling doc.destroy unregisters it', function(done) { + var connection = this.connection; + var doc = connection.get('dogs', 'fido'); + expect(connection.getExisting('dogs', 'fido')).equal(doc); - doc.destroy(); - expect(this.connection.getExisting('dogs', 'fido')).equal(undefined); + doc.destroy(function(err) { + if (err) return done(err); + expect(connection.getExisting('dogs', 'fido')).equal(undefined); - var doc2 = this.connection.get('dogs', 'fido'); - expect(doc).not.equal(doc2); + var doc2 = connection.get('dogs', 'fido'); + expect(doc).not.equal(doc2); + done(); + }); + + // destroy is async + expect(connection.getExisting('dogs', 'fido')).equal(doc); }); - it('getting then destroying then getting returns a new doc object', function() { - var doc = this.connection.get('dogs', 'fido'); - doc.destroy(); - var doc2 = this.connection.get('dogs', 'fido'); - expect(doc).not.equal(doc2); - expect(doc).eql(doc2); + it('getting then destroying then getting returns a new doc object', function(done) { + var connection = this.connection; + var doc = connection.get('dogs', 'fido'); + doc.destroy(function(err) { + if (err) return done(err); + var doc2 = connection.get('dogs', 'fido'); + expect(doc).not.equal(doc2); + expect(doc).eql(doc2); + done(); + }); }); - it('doc.destroy() calls back', function(done) { + it('doc.destroy() works without a callback', function() { var doc = this.connection.get('dogs', 'fido'); - doc.destroy(done); + doc.destroy(); }); describe('applyStack', function() { From 7c846217f25fe4aaafdd427268ac2695bd7695a0 Mon Sep 17 00:00:00 2001 From: Greg Kubisa Date: Thu, 12 Jul 2018 13:30:49 +0200 Subject: [PATCH 2/3] Update tested nodejs versions --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7bd066b20..21efafe46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: node_js node_js: - "10" - - "9" - "8" - "6" - - "4" 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" From 065ed9dc5c9f3246310d6c79d08650bc197b2b8f Mon Sep 17 00:00:00 2001 From: Greg Kubisa Date: Mon, 5 Nov 2018 11:50:09 +0000 Subject: [PATCH 3/3] Remove some unnecessary code --- lib/client/doc.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/client/doc.js b/lib/client/doc.js index 2c60ee25e..ce152cd8e 100644 --- a/lib/client/doc.js +++ b/lib/client/doc.js @@ -204,10 +204,6 @@ Doc.prototype.ingestSnapshot = function(snapshot, callback) { }; Doc.prototype.whenNothingPending = function(callback) { - if (this.hasPending()) { - this.once('nothing pending', callback); - return; - } var doc = this; process.nextTick(function() { if (doc.hasPending()) {