-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const test = require('brittle') | ||
const { create, replicate } = require('./helpers') | ||
|
||
test('basic peer remote contiguous length', async function (t) { | ||
t.plan(2) | ||
|
||
const a = await create() | ||
const b = await create(a.key) | ||
|
||
replicate(a, b, t) | ||
|
||
await a.append('a') | ||
await b.get(0) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 1) | ||
|
||
await a.append('b') | ||
await b.get(1) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 2) | ||
}) | ||
|
||
test('peer remote contiguous length', async function (t) { | ||
t.plan(3) | ||
|
||
const a = await create() | ||
const b = await create(a.key) | ||
|
||
replicate(a, b, t) | ||
|
||
await a.append('a') | ||
await b.get(0) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 1) | ||
|
||
await a.append(['d', 'e']) | ||
await b.get(2) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 1) | ||
|
||
await b.get(1) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 3) | ||
}) | ||
|
||
test('peer truncates the remote contiguous length', async function (t) { | ||
t.plan(2) | ||
|
||
const a = await create() | ||
const b = await create(a.key) | ||
|
||
replicate(a, b, t) | ||
|
||
await a.append(['a', 'b']) | ||
await b.get(0) | ||
await b.get(1) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 2) | ||
|
||
await a.truncate(1) | ||
await new Promise(resolve => setTimeout(resolve, 100)) | ||
t.is(getPeer(a, b).remoteContiguousLength, 1) | ||
}) | ||
|
||
// "A" wants to know if "B" is finished syncing, so find the corresponding peer | ||
function getPeer (a, b) { | ||
return a.replicator.peers.find(peer => peer.remotePublicKey.equals(b.replicator.peers[0].stream.publicKey)) | ||
} |