Skip to content

Commit

Permalink
Replication fixes with 3 writers (#116)
Browse files Browse the repository at this point in the history
Added a .watch() test for a 3 writer scenario where the third
writer joins after the .watch() is started.

Update the logic for _maybeUpdateFeeds to avoid 'Missing feed mappings'
assertions.
  • Loading branch information
jimpick authored and mafintosh committed May 4, 2018
1 parent 0451697 commit 330cf04
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,13 @@ Writer.prototype._needsInflate = function () {

Writer.prototype._maybeUpdateFeeds = function () {
if (!this._feedsMessage) return
if (this._decodeMap.length === this._db.feeds.length) return
if (this._encodeMap.length === this._db.feeds.length) return
this._updateFeeds()
var writers = this._feedsMessage.feeds || []
if (
this._decodeMap.length !== writers.length ||
this._encodeMap.length !== this._db.feeds.length
) {
this._updateFeeds()
}
}

Writer.prototype._decode = function (seq, buf, cb) {
Expand Down
29 changes: 29 additions & 0 deletions test/watch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var tape = require('tape')
var create = require('./helpers/create')
var replicate = require('./helpers/replicate')
var run = require('./helpers/run')

tape('basic watch', function (t) {
var db = create.one()
Expand Down Expand Up @@ -79,3 +80,31 @@ tape('remote watch', function (t) {
})
})
})

tape('watch with 3rd-party authorize', function (t) {
create.two(function (a, b) {
t.plan(2)

a.watch(function () {
t.pass('watch called')
})

var c = create.one(a.key)
c.ready(function () {
run(
cb => replicate(a, b, cb),
cb => replicate(b, c, cb),
cb => b.authorize(c.local.key, cb),
cb => replicate(b, c, cb),
cb => c.put('hello2', 'world2', cb),
cb => replicate(b, c, cb),
cb => replicate(a, b, cb),
done
)

function done (err) {
t.error(err, 'no error')
}
})
})
})

0 comments on commit 330cf04

Please sign in to comment.