Skip to content

Commit

Permalink
Make sure member count is accurate when writer rejoining (#167)
Browse files Browse the repository at this point in the history
* add test for removing and rejoining

* removed writer does not count as tracked
  • Loading branch information
chm-diederichs authored Aug 7, 2024
1 parent d11c155 commit ada4f41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ada4f41

Please sign in to comment.