From ada4f4181bd03b1243398857a8e8d8871b35a9ce Mon Sep 17 00:00:00 2001 From: Christophe Diederichs <45171645+chm-diederichs@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:14:27 +0200 Subject: [PATCH] Make sure member count is accurate when writer rejoining (#167) * add test for removing and rejoining * removed writer does not count as tracked --- lib/system.js | 4 ++-- test/basic.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/system.js b/lib/system.js index e2a7cacd..53bca119 100644 --- a/lib/system.js +++ b/lib/system.js @@ -305,11 +305,11 @@ module.exports = class SystemView extends ReadyResource { cas (older, newer) { if (older === null) return true - wasTracked = true - const o = older.value const n = newer.value + if (!o.isRemoved) wasTracked = true + if (length === 0 && o.length) length = o.length return o.isRemoved !== n.isRemoved || o.isIndexer !== n.isIndexer || o.length !== n.length diff --git a/test/basic.js b/test/basic.js index b453a4e3..870f025e 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1088,6 +1088,31 @@ test('basic - remove writer', async t => { t.is(b.system.members, c.system.members) }) +test('basic - remove and rejoin writer', async t => { + const { bases } = await create(2, t, { apply: applyWithRemove, open: null }) + const [a, b] = bases + + await addWriter(a, b, false) + await confirm([a, b]) + + t.is(a.system.members, 2) + + await a.append({ remove: b4a.toString(b.local.key, 'hex') }) + await confirm([a, b]) + + t.is(a.system.members, 1) + + await addWriter(a, b, false) + await confirm([a, b]) + + t.is(a.system.members, 2) + + await a.append({ remove: b4a.toString(b.local.key, 'hex') }) + await confirm([a, b]) + + t.is(a.system.members, 1) +}) + test('basic - non-indexer writer removes themselves', async t => { const { bases } = await create(2, t, { apply: applyWithRemove, open: null }) const [a, b] = bases