Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add failing test for pub case #75

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions test/pub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const tape = require('tape')
const crypto = require('crypto')
const SecretStack = require('secret-stack')
const { promisify: pify } = require('util')

const u = require('./misc/util')

const sleep = pify(setTimeout)
const caps = {
shs: crypto.randomBytes(32).toString('base64'),
}

const CONNECTION_TIMEOUT = 500 // ms
const REPLICATION_TIMEOUT = 2 * CONNECTION_TIMEOUT

function Server(name, opts = {}) {
const stack = SecretStack({ caps }).use(require('ssb-db')).use(require('../'))

return stack({
temp: `test-pub-replicate-${name}`, // ssb-db only
timeout: CONNECTION_TIMEOUT,
keys: u.keysFor(name),
...opts,
})
}

tape('Pub replicates Alice', async (t) => {
const aliceKeys = u.keysFor('alice')

const alice = Server('alice', { keys: aliceKeys })
const pub = Server('pub')

await pify(alice.publish)({ type: 'post', text: 'hello!' })
await pify(alice.publish)({ type: 'post', text: 'hello again' })

// Pub set up to want Alice's feed
pub.ebt.request(alice.id, true)
// alice.ebt.request(alice.id, true) // MYSTERY - replication fails without this
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Solution" 🙈

if we have alice request herself before the connection, the replication to the pub works. This is very counter-intuitive. Seems like a bug not a feature.


// Alice connects (as Client) to Pub
await pify(alice.connect)(pub.getAddress())

await sleep(REPLICATION_TIMEOUT)
t.deepEqual(
await pify(pub.ebt.clock)(),
{
[alice.id]: 2,
},
"pub: clock shows has alice's messages"
)

await Promise.all([pify(alice.close)(true), pify(pub.close)(true)]).catch(
t.error
)

t.end()
})