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 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move tests and add benchmark runs
- Loading branch information
Showing
12 changed files
with
776 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package-lock.json | ||
yarn.lock | ||
docs | ||
|
||
**/node_modules | ||
**/*.log | ||
test/setup/tmp-disposable-nodes-addrs.json | ||
dist | ||
coverage | ||
**/*.swp | ||
examples/sub-module/**/bundle.js | ||
examples/sub-module/**/*-minified.js | ||
examples/sub-module/*-bundle.js |
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,18 @@ | ||
{ | ||
"name": "libp2p-mplex-profile", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "profile.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"async": "^2.6.0", | ||
"libp2p-mplex": "0.7.0", | ||
"pull-generate": "^2.2.0", | ||
"pull-pair": "^1.1.0", | ||
"pull-stream": "^3.6.8" | ||
} | ||
} |
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,85 @@ | ||
'use strict' | ||
|
||
const pair = require('pull-pair/duplex') | ||
const pull = require('pull-stream') | ||
const generate = require('pull-generate') | ||
const each = require('async/each') | ||
const eachLimit = require('async/eachLimit') | ||
const setImmediate = require('async/setImmediate') | ||
|
||
const Plex = require('libp2p-mplex') | ||
|
||
const spawn = (nStreams, nMsg, done, limit) => { | ||
const p = pair() | ||
|
||
const check = marker(2 * nStreams, done) | ||
|
||
const msg = 'simple msg' | ||
|
||
const listener = Plex.dialer(p[0]) | ||
const dialer = Plex.listener(p[1]) | ||
|
||
listener.on('stream', (stream) => { | ||
pull( | ||
stream, | ||
pull.onEnd((err) => { | ||
if (err) { return done(err) } | ||
check() | ||
pull(pull.empty(), stream) | ||
}) | ||
) | ||
}) | ||
|
||
const numbers = [] | ||
for (let i = 0; i < nStreams; i++) { | ||
numbers.push(i) | ||
} | ||
|
||
const spawnStream = (n, cb) => { | ||
const stream = dialer.newStream() | ||
pull( | ||
generate(0, (s, cb) => { | ||
setImmediate(() => { | ||
cb(s === nMsg ? true : null, msg, s + 1) | ||
}) | ||
}), | ||
stream, | ||
pull.collect((err) => { | ||
if (err) { return done(err) } | ||
check() | ||
cb() | ||
}) | ||
) | ||
} | ||
|
||
if (limit) { | ||
eachLimit(numbers, limit, spawnStream, () => {}) | ||
} else { | ||
each(numbers, spawnStream, () => {}) | ||
} | ||
} | ||
|
||
function marker (n, done) { | ||
let i = 0 | ||
return (err) => { | ||
i++ | ||
|
||
// console.log(`${i} out of ${n} interactions`) | ||
if (err) { | ||
console.error('Failed after %s iterations', i) | ||
return done(err) | ||
} | ||
|
||
if (i === n) { | ||
done() | ||
} | ||
} | ||
} | ||
|
||
spawn(1000, 1000, (err) => { | ||
if (err) { | ||
throw err | ||
} | ||
console.log('Done') | ||
process.exit(0) | ||
}, 50000) |
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,13 @@ | ||
package-lock.json | ||
yarn.lock | ||
docs | ||
|
||
**/node_modules | ||
**/*.log | ||
test/setup/tmp-disposable-nodes-addrs.json | ||
dist | ||
coverage | ||
**/*.swp | ||
examples/sub-module/**/bundle.js | ||
examples/sub-module/**/*-minified.js | ||
examples/sub-module/*-bundle.js |
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,17 @@ | ||
{ | ||
"name": "pull-mplex-profile", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "profile.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"async": "^2.6.0", | ||
"pull-generate": "^2.2.0", | ||
"pull-pair": "^1.1.0", | ||
"pull-stream": "^3.6.8" | ||
} | ||
} |
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,85 @@ | ||
'use strict' | ||
|
||
const pair = require('pull-pair/duplex') | ||
const pull = require('pull-stream') | ||
const generate = require('pull-generate') | ||
const each = require('async/each') | ||
const eachLimit = require('async/eachLimit') | ||
const setImmediate = require('async/setImmediate') | ||
|
||
const Plex = require('../../src') | ||
|
||
const spawn = (nStreams, nMsg, done, limit) => { | ||
const p = pair() | ||
|
||
const check = marker(2 * nStreams, done) | ||
|
||
const msg = 'simple msg' | ||
|
||
const listener = Plex.dialer(p[0]) | ||
const dialer = Plex.listener(p[1]) | ||
|
||
listener.on('stream', (stream) => { | ||
pull( | ||
stream, | ||
pull.onEnd((err) => { | ||
if (err) { return done(err) } | ||
check() | ||
pull(pull.empty(), stream) | ||
}) | ||
) | ||
}) | ||
|
||
const numbers = [] | ||
for (let i = 0; i < nStreams; i++) { | ||
numbers.push(i) | ||
} | ||
|
||
const spawnStream = (n, cb) => { | ||
const stream = dialer.newStream() | ||
pull( | ||
generate(0, (s, cb) => { | ||
setImmediate(() => { | ||
cb(s === nMsg ? true : null, msg, s + 1) | ||
}) | ||
}), | ||
stream, | ||
pull.collect((err) => { | ||
if (err) { return done(err) } | ||
check() | ||
cb() | ||
}) | ||
) | ||
} | ||
|
||
if (limit) { | ||
eachLimit(numbers, limit, spawnStream, () => {}) | ||
} else { | ||
each(numbers, spawnStream, () => {}) | ||
} | ||
} | ||
|
||
function marker (n, done) { | ||
let i = 0 | ||
return (err) => { | ||
i++ | ||
|
||
// console.log(`${i} out of ${n} interactions`) | ||
if (err) { | ||
console.error('Failed after %s iterations', i) | ||
return done(err) | ||
} | ||
|
||
if (i === n) { | ||
done() | ||
} | ||
} | ||
} | ||
|
||
spawn(1000, 1000, (err) => { | ||
if (err) { | ||
throw err | ||
} | ||
console.log('Done') | ||
process.exit(0) | ||
}, 50000) |
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,11 @@ | ||
## Old node stream based interop tests | ||
|
||
### What is this? | ||
|
||
This will install libp2p-mplex version `0.7.0` and run tests against it using the new `pull-mplex` implementation. This needs to be a separate packages because we can't install `libp2p-mplex` into `libp2p-mplex` ;( | ||
|
||
### To run the tests do: | ||
|
||
``` | ||
npm i && npm run test | ||
``` |
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,18 @@ | ||
{ | ||
"name": "old-new-interop", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "stream-mplex-interop.spec.js", | ||
"scripts": { | ||
"test": "aegir test -t node browser -f test/stream-mplex-interop.js" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"chunky": "0.0.0", | ||
"concat-stream": "^1.6.2", | ||
"libp2p-mplex": "0.7.0", | ||
"pull-stream-to-stream": "^1.3.4", | ||
"through2": "^2.0.3" | ||
} | ||
} |
Oops, something went wrong.