This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding nyc for code coverage adding replicator tests linting Fix replications tests, add more debug output Fix linter fixing ipfs config in tests fix: linting
- Loading branch information
Showing
9 changed files
with
1,097 additions
and
396 deletions.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,126 @@ | ||
const assert = require('assert') | ||
const Log = require('ipfs-log') | ||
|
||
const Keystore = require('orbit-db-keystore') | ||
const IdentityProvider = require('orbit-db-identity-provider') | ||
const Replicator = require('../src/Replicator') | ||
|
||
const { | ||
connectPeers, | ||
config, | ||
testAPIs, | ||
startIpfs, | ||
stopIpfs | ||
} = require('orbit-db-test-utils') | ||
|
||
// Tests timeout | ||
const timeout = 30000 | ||
|
||
class DummyStore { | ||
constructor (log, ipfs, identity) { | ||
this._oplog = log | ||
this._ipfs = ipfs | ||
this.identity = identity | ||
} | ||
|
||
async close () {} | ||
} | ||
|
||
Object.keys(testAPIs).forEach((IPFS) => { | ||
describe(`Replicator, ${IPFS}`, function () { | ||
this.timeout(timeout) | ||
|
||
let log, ipfsd, ipfs, replicator, store, keystore, signingKeystore | ||
|
||
const { identityKeysPath } = config | ||
|
||
before(async () => { | ||
keystore = new Keystore(identityKeysPath) | ||
|
||
ipfsd = await startIpfs(IPFS, config.daemon1) | ||
ipfs = ipfsd.api | ||
const id = await ipfsd.api.id() | ||
|
||
const testIdentity = await IdentityProvider.createIdentity({ id, keystore }) | ||
log = new Log(ipfs, testIdentity) | ||
|
||
store = new DummyStore(log, ipfs, testIdentity) | ||
replicator = new Replicator(store, 123) | ||
}) | ||
|
||
after(async () => { | ||
await store.close() | ||
await stopIpfs(ipfsd) | ||
await replicator.stop() | ||
await keystore.close() | ||
}) | ||
|
||
it('default options', async () => { | ||
assert.deepStrictEqual(replicator._buffer, []) | ||
}) | ||
|
||
describe('concurrency = 1', function () { | ||
let ipfsd2, ipfs2, log2, store2 | ||
|
||
this.timeout(timeout) | ||
|
||
const logLength = 100 | ||
|
||
before(async () => { | ||
ipfsd2 = await startIpfs(IPFS, config.daemon2) | ||
ipfs2 = ipfsd2.api | ||
await connectPeers(ipfs, ipfs2) | ||
|
||
const testIdentity = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) | ||
log2 = new Log(ipfs2, testIdentity, { logId: log.id }) | ||
|
||
console.log(`writing ${logLength} entries to the log`) | ||
for (let i = 0; i < logLength; i++) { | ||
await log2.append(`entry${i}`) | ||
} | ||
assert(log2.values.length, logLength) | ||
|
||
store2 = new DummyStore(log2, ipfs2, testIdentity) | ||
}) | ||
|
||
after(async () => { | ||
await store2.close() | ||
await stopIpfs(ipfsd2) | ||
}) | ||
|
||
it('loads', (done) => { | ||
let replicated = 0 | ||
|
||
assert.strictEqual(log.id, log2.id) | ||
|
||
replicator.load(log2.heads) | ||
|
||
assert.strictEqual(replicator._buffer.length, 0) | ||
assert.deepStrictEqual(replicator.getQueue()[0], log2.heads[0]) | ||
assert.strictEqual(replicator.tasksQueued, 1) | ||
assert.strictEqual(replicator.tasksRequested, 1) | ||
assert.strictEqual(replicator.tasksStarted, 0) // ?? | ||
|
||
replicator.on('load.end', async (replicatedLogs) => { | ||
replicated++ | ||
assert.strictEqual(replicator.tasksStarted, replicated) // ?? | ||
assert.strictEqual(replicator.tasksQueued, 0) | ||
assert.strictEqual(replicator.tasksFinished, replicated) | ||
// console.log(replicatedLogs.length) | ||
for (const replicatedLog of replicatedLogs) { | ||
// console.log(replicatedLog.values.length, log.values.length, replicatedLog.values[0]) | ||
await log.join(replicatedLog) | ||
} | ||
// console.log(log.values.length) | ||
// console.log(log.values[0].payload) | ||
// console.log(log.values.map(e => e.payload).join('\n')) | ||
|
||
if (log.values.length === logLength) { | ||
assert.deepStrictEqual(log.values, log2.values) | ||
done() | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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