Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lib/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,12 @@ module.exports = class Replicator {
}

this._onpeerupdate(false, peer)
if (inflight) this.updateAll()
if (inflight) {
this.updateAll()
} else {
this._checkUpgradeIfAvailable()
this._maybeResolveIfAvailableRanges()
}
}

_queueBlock(b) {
Expand Down
35 changes: 35 additions & 0 deletions test/replicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,41 @@ test('findingPeers + done makes update return false if no peers', async function
t.is(await u, false)
})

test('update wait resolves when unsynced peer closes without inflight', async function (t) {
t.plan(2)

const a = await create(t)
const b = await create(t, a.key)

let streams = null
let update = null

const peerAdded = new Promise((resolve) => {
b.once('peer-add', () => {
update = b.update({ wait: true })

Promise.resolve().then(() => {
resolve(unreplicate(streams))
})
})
})

streams = replicate(a, b, t, { teardown: false })

await peerAdded

let timer = null
const timeout = new Promise((resolve) => {
timer = setTimeout(resolve, 250, null)
})

const result = await Promise.race([update, timeout])
clearTimeout(timer)

t.not(result, null, 'update resolved')
t.is(result, false, 'no upgrade was available')
})

test.skip('can disable downloading from a peer', async function (t) {
const a = await create(t)

Expand Down
Loading