diff --git a/lib/index.js b/lib/index.js index 13d3e3c..eef3c6e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,6 +2,7 @@ const makeDebug = require('debug') const MsgV4 = require('pzp-db/msg-v4') /** + * @typedef {import('pzp-db').RecPresent} Rec * @typedef {ReturnType} PZPDB * @typedef {ReturnType} PZPGoal * @typedef {import('pzp-goals').GoalDSL} GoalDSL @@ -276,6 +277,10 @@ function initConductor(peer, config) { peer.gc.start(maxBytes) peer.sync.start() + peer.db.onRecordAdded((/** @type {Rec} */ { id: msgID, msg }) => { + peer.sync.start() + }) + cb() }) } diff --git a/package.json b/package.json index 3e1fcdd..69dd79e 100644 --- a/package.json +++ b/package.json @@ -31,17 +31,17 @@ "bs58": "^5.0.0", "c8": "7", "pzp-caps": "^1.0.0", - "pzp-db": "^1.0.1", - "pzp-dict": "^1.0.0", + "pzp-db": "^1.0.4", + "pzp-dict": "^1.0.1", "pzp-gc": "^1.0.0", - "pzp-goals": "^1.0.0", + "pzp-goals": "^1.0.1", "pzp-keypair": "^1.0.0", - "pzp-set": "^1.0.0", - "pzp-sync": "^1.0.0", + "pzp-set": "^1.0.1", + "pzp-sync": "^1.0.4", "prettier": "^2.6.2", "pretty-quick": "^3.1.3", "rimraf": "^4.4.0", - "secret-handshake-ext": "~0.0.11", + "secret-handshake-ext": "~0.0.12", "secret-stack": "~8.1.0", "ssb-box": "^1.0.1", "typescript": "^5.4.5" diff --git a/test/realtime.test.js b/test/realtime.test.js index 95e963d..31bfcc5 100644 --- a/test/realtime.test.js +++ b/test/realtime.test.js @@ -39,6 +39,13 @@ test('create 200 messages that manage to replicate with low "newest" goals', asy assert.deepEqual(arr, [], 'alice has no posts from bob') } + // TODO: make things work with this first, then add another test without this? + await p(bob.db.feed.publish)({ + account: bobID, + domain: 'post', + data: { text: `${n}` }, + }) + const confirmed = [] // for keeping track of which msgs have arrived for (let i = 0; i < n; i++) { @@ -47,6 +54,7 @@ test('create 200 messages that manage to replicate with low "newest" goals', asy alice.db.onRecordAdded(rec => { if (rec.msg.data?.text) { + //console.log('alice received rec', rec) const num = Number.parseInt(rec.msg.data.text) confirmed[num] = true } @@ -55,20 +63,17 @@ test('create 200 messages that manage to replicate with low "newest" goals', asy await p(alice.set.load)(aliceID) await p(bob.set.load)(bobID) - // TODO: do we need to follow each other? + // TODO: do we need to follow? probably assert(await p(alice.set.add)('follows', bobID), 'alice follows bob') + // TODO: remove this one + assert(await p(bob.set.add)('follows', aliceID), 'alice follows bob') - //bob.goals.set(bobPostsID, 'newest-50') - //alice.goals.set(bobPostsID, 'newest-50') - // TODO: lower to newest-50, alice then bob - // supposedly [myrules, theirrules], do they need to match? - await p(alice.conductor.start)(aliceID, [['post@all'], ['post@all']], 64_000_000) - await p(bob.conductor.start)(bobID, [['post@all'], ['post@all']], 64_000_000) + await p(alice.conductor.start)(aliceID, [['post@newest-50'], ['post@newest-50']], 64_000_000) + await p(bob.conductor.start)(bobID, [['post@newest-50'], ['post@newest-50']], 64_000_000) const remoteAlice = await p(bob.connect)(alice.getAddress()) assert('alice and bob connected') - bob.sync.start() await p(setTimeout)(1000) assert('sync!') @@ -83,14 +88,13 @@ test('create 200 messages that manage to replicate with low "newest" goals', asy }))) assert(`bob published ${n} posts in parallel`) - //let tries = 30 - let tries = 100 + let tries = 30 // just waiting for them to arrive do { await p(setTimeout)(100) } while (!confirmed.every(v => v === true) && tries-- > 0) - assert.equal(confirmed.filter(v => v === true).length, n, `alice has all of bob's posts`) + assert.equal(confirmed.filter(v => v === true).length, n + 1, `alice has all of bob's posts including the initial one`) await p(remoteAlice.close)(true) await p(alice.close)(true)