-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from orbitdb/new-refactor-2-rename
New refactor 2 rename
- Loading branch information
Showing
5 changed files
with
77 additions
and
109 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
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 |
---|---|---|
@@ -1,108 +1,79 @@ | ||
// import { multiaddr } from '@multiformats/multiaddr' | ||
import { strictEqual, deepStrictEqual } from 'assert' | ||
import { rimraf } from 'rimraf' | ||
import { launchLander } from './utils/launch-lander.js' | ||
import { launchOrbiter } from './utils/launch-orbiter.js' | ||
import waitFor from './utils/wait-for.js' | ||
// import connectPeers from './utils/connect-nodes-via-relay.js' | ||
|
||
// const isBrowser = () => typeof window !== 'undefined' | ||
describe('Stress test', function () { | ||
this.timeout(10000000) | ||
|
||
describe('End-to-End Browser Tests', function () { | ||
describe('Orbiter in the browser', function () { | ||
this.timeout(10000000) | ||
let orbiter | ||
let lander1 | ||
let lander2 | ||
|
||
// const orbiterAddress1 = isBrowser() | ||
// ? multiaddr('/ip4/127.0.0.1/tcp/55441/ws/p2p/16Uiu2HAmBzKcgCfpJ4j4wJSLkKLbCVvnNBWPnhexrnJWJf1fDu5y') | ||
// : multiaddr('/ip4/127.0.0.1/tcp/54321/p2p/16Uiu2HAmBzKcgCfpJ4j4wJSLkKLbCVvnNBWPnhexrnJWJf1fDu5y') | ||
|
||
// const orbiterAddress2 = isBrowser() | ||
// ? multiaddr('/ip4/127.0.0.1/tcp/55442/ws/p2p/16Uiu2HAmATMovCwY46yyJib7bGZF2f2XLRar7d7R3NJCSJtuyQLt') | ||
// : multiaddr('/ip4/127.0.0.1/tcp/54322/p2p/16Uiu2HAmATMovCwY46yyJib7bGZF2f2XLRar7d7R3NJCSJtuyQLt') | ||
|
||
let orbiter | ||
let lander1 | ||
let lander2 | ||
|
||
before(async function () { | ||
orbiter = await launchOrbiter({ directory: 'orbiter3' }) | ||
}) | ||
|
||
after(async function () { | ||
if (orbiter) { | ||
await orbiter.shutdown() | ||
} | ||
await rimraf('./orbiter3') | ||
}) | ||
|
||
it('add and replicate a database - lander1->orbiter1(nodejs)->orbiter2(nodejs)->lander2', async function () { | ||
const rounds = 50 | ||
const entryAmount = 100 | ||
const addr = orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().shift() | ||
before(async function () { | ||
orbiter = await launchOrbiter({ directory: 'orbiter3' }) | ||
}) | ||
|
||
console.log('start', addr) | ||
for (let k = 1; k <= rounds; k++) { | ||
let replicated = false | ||
after(async function () { | ||
if (orbiter) { | ||
await orbiter.shutdown() | ||
} | ||
await rimraf('./orbiter3') | ||
}) | ||
|
||
// lander1 = await launchLander({ orbiterAddress: orbiterAddress1, directory: 'lander4' }) | ||
lander1 = await launchLander({ orbiterAddress: addr, directory: 'lander4' }) | ||
await orbiter.auth.add(lander1.orbitdb.identity.id) | ||
it('add and replicate a database - lander1->orbiter1->lander2', async function () { | ||
const rounds = 50 | ||
const entryAmount = 100 | ||
const addr = orbiter.orbitdb.ipfs.libp2p.getMultiaddrs().shift() | ||
|
||
const db1 = await lander1.orbitdb.open('my-db3') | ||
for (let k = 1; k <= rounds; k++) { | ||
let replicated = false | ||
|
||
// console.log("--", lander1.orbitdb.ipfs.libp2p.peerId.toString(), db1.address) | ||
lander1 = await launchLander({ orbiterAddress: addr, directory: 'lander4' }) | ||
await orbiter.auth.add(lander1.orbitdb.identity.id) | ||
|
||
for (let i = 0; i < entryAmount; i++) { | ||
await db1.add('hello world ' + i) | ||
} | ||
const db1 = await lander1.orbitdb.open('my-db3') | ||
|
||
const expected = await db1.all() | ||
for (let i = 0; i < entryAmount; i++) { | ||
await db1.add('hello world ' + i) | ||
} | ||
|
||
// console.time('pin') | ||
await lander1.add(db1.address) | ||
// console.timeEnd('pin') | ||
const expected = await db1.all() | ||
|
||
await lander1.shutdown() | ||
await lander1.add(db1.address) | ||
|
||
lander2 = await launchLander({ orbiterAddress: addr, directory: 'lander5' }) | ||
await orbiter.auth.add(lander2.orbitdb.identity.id) | ||
// lander2 = await launchLander({ orbiterAddress: orbiterAddress1, directory: 'lander5' }) | ||
await lander1.shutdown() | ||
|
||
// console.time('pin2') | ||
// await lander2.pin(db1.address) | ||
// console.timeEnd('pin2') | ||
lander2 = await launchLander({ orbiterAddress: addr, directory: 'lander5' }) | ||
await orbiter.auth.add(lander2.orbitdb.identity.id) | ||
|
||
// console.time('replicate') | ||
// console.log("open", db1.address) | ||
console.time('round ' + k + '/' + rounds) | ||
const db2 = await lander2.orbitdb.open(db1.address) | ||
console.time('round ' + k + '/' + rounds) | ||
const db2 = await lander2.orbitdb.open(db1.address) | ||
|
||
const onConnected = (peerId, heads) => { | ||
replicated = true | ||
} | ||
const onConnected = (peerId, heads) => { | ||
replicated = true | ||
} | ||
|
||
db2.events.on('join', onConnected) | ||
db2.events.on('join', onConnected) | ||
|
||
await waitFor(() => replicated, () => true) | ||
// console.timeEnd('replicate') | ||
console.timeEnd('round ' + k + '/' + rounds) | ||
await waitFor(() => replicated, () => true) | ||
console.timeEnd('round ' + k + '/' + rounds) | ||
|
||
const res = await db2.all() | ||
const res = await db2.all() | ||
|
||
strictEqual(expected.length, entryAmount) | ||
strictEqual(res.length, entryAmount) | ||
deepStrictEqual(expected, res) | ||
// console.log('done ' + k + "/" + rounds) | ||
strictEqual(expected.length, entryAmount) | ||
strictEqual(res.length, entryAmount) | ||
deepStrictEqual(expected, res) | ||
|
||
if (lander1) { | ||
await lander1.shutdown() | ||
} | ||
if (lander2) { | ||
await lander2.shutdown() | ||
} | ||
await rimraf('./lander4') | ||
await rimraf('./lander5') | ||
if (lander1) { | ||
await lander1.shutdown() | ||
} | ||
if (lander2) { | ||
await lander2.shutdown() | ||
} | ||
}) | ||
await rimraf('./lander4') | ||
await rimraf('./lander5') | ||
} | ||
}) | ||
}) |
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,9 @@ | ||
const waitForDaemonStarted = async (daemon) => { | ||
return new Promise((resolve) => { | ||
// Wait for the daemon to start which is when the daemon has printed "started" in stdout | ||
const onStdout = (data) => (data.toString().trimRight() === 'started') ? resolve() : {} | ||
daemon.stdout.on('data', onStdout) | ||
}) | ||
} | ||
|
||
export default waitForDaemonStarted |