This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
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
8 changed files
with
105 additions
and
77 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
File renamed without changes.
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,31 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { expect } from 'aegir/chai' | ||
import range from 'lodash.range' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import { Message } from '../src/message/index.js' | ||
import { isPeerId } from '@libp2p/interface-peer-id' | ||
|
||
describe('Message', () => { | ||
it('go-interop', () => { | ||
range(1, 9).forEach((i) => { | ||
const raw = fs.readFileSync( | ||
path.join(process.cwd(), 'test', 'fixtures', `msg-${i}`) | ||
) | ||
|
||
const msg = Message.deserialize(raw) | ||
|
||
expect(msg.clusterLevel).to.gte(0) | ||
if (msg.record != null) { | ||
expect(msg.record.key).to.be.a('Uint8Array') | ||
} | ||
|
||
if (msg.providerPeers.length > 0) { | ||
msg.providerPeers.forEach((p) => { | ||
expect(isPeerId(p.id)).to.be.true() | ||
}) | ||
} | ||
}) | ||
}) | ||
}) |
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,63 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { LevelDatastore } from 'datastore-level' | ||
import path from 'path' | ||
import os from 'os' | ||
import { Providers } from '../src/providers.js' | ||
import { createValues } from './utils/create-values.js' | ||
import { createPeerIds } from './utils/create-peer-id.js' | ||
import { MemoryDatastore } from 'datastore-core/memory' | ||
|
||
describe('Providers', () => { | ||
let providers: Providers | ||
|
||
before(async function () { | ||
this.timeout(10 * 1000) | ||
}) | ||
|
||
afterEach(async () => { | ||
await providers?.stop() | ||
}) | ||
|
||
// slooow so only run when you need to | ||
it.skip('many', async function () { | ||
const p = path.join( | ||
os.tmpdir(), (Math.random() * 100).toString() | ||
) | ||
const store = new LevelDatastore(p) | ||
await store.open() | ||
providers = new Providers({ | ||
datastore: new MemoryDatastore() | ||
}, { | ||
cacheSize: 10 | ||
}) | ||
|
||
console.log('starting') // eslint-disable-line no-console | ||
const [createdValues, createdPeers] = await Promise.all([ | ||
createValues(100), | ||
createPeerIds(600) | ||
]) | ||
|
||
console.log('got values and peers') // eslint-disable-line no-console | ||
const total = Date.now() | ||
|
||
for (const v of createdValues) { | ||
for (const p of createdPeers) { | ||
await providers.addProvider(v.cid, p) | ||
} | ||
} | ||
|
||
console.log('addProvider %s peers %s cids in %sms', createdPeers.length, createdValues.length, Date.now() - total) // eslint-disable-line no-console | ||
console.log('starting profile with %s peers and %s cids', createdPeers.length, createdValues.length) // eslint-disable-line no-console | ||
|
||
for (let i = 0; i < 3; i++) { | ||
const start = Date.now() | ||
for (const v of createdValues) { | ||
await providers.getProviders(v.cid) | ||
console.log('query %sms', (Date.now() - start)) // eslint-disable-line no-console | ||
} | ||
} | ||
|
||
await store.close() | ||
}) | ||
}) |
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