This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
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
7 changed files
with
166 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
// const parallel = require('run-parallel') | ||
|
||
const createTempNode = require('../../utils/temp-node') | ||
const spawnNode = require('../../utils/spawn-ipfs-node').spawnNode | ||
|
||
describe('network stress tests', function () { | ||
this.timeout(20 * 1000) | ||
|
||
describe('1 connected node (TCP)', () => { | ||
let node | ||
let subNodes = [] | ||
|
||
it('spawn in process node', (done) => { | ||
createTempNode(100, (err, tmpNode) => { | ||
expect(err).to.not.exist | ||
node = tmpNode | ||
done() | ||
}) | ||
}) | ||
|
||
it('start node', (done) => { | ||
node.goOnline(done) | ||
}) | ||
|
||
it('spawn a node in a child process', (done) => { | ||
spawnNode(['tcp'], (err, subNode) => { | ||
expect(err).to.not.exist | ||
subNode.addr = subNode.nodeInfo.Addresses[0] + '/ipfs/' + subNode.nodeInfo.ID | ||
subNodes.push(subNode) | ||
console.log('spawn:', subNode.addr) | ||
done() | ||
}) | ||
}) | ||
|
||
it('connect to child node', (done) => { | ||
node.libp2p.swarm.connect(subNodes[0].addr, done) | ||
}) | ||
|
||
it.skip('do not crash if there is a stream hanging', (done) => { | ||
node._libp2pNode.dialByMultiaddr(subNodes[0].addr, '/echo/1.0.0', (err, conn) => { | ||
expect(err).to.not.exist | ||
done() | ||
}) | ||
}) | ||
|
||
it('send 10000 msg', (done) => { | ||
node._libp2pNode.dialByMultiaddr(subNodes[0].addr, '/echo/1.0.0', (err, conn) => { | ||
expect(err).to.not.exist | ||
conn.resume() | ||
conn.end() | ||
conn.on('end', done) | ||
}) | ||
}) | ||
|
||
it.skip('send 10000 msg (2x)', (done) => {}) | ||
|
||
it.skip('send 10000 msg (3x)', (done) => {}) | ||
|
||
it('kill child node', (done) => { | ||
subNodes[0].sigkill() | ||
setTimeout(done, 200) | ||
}) | ||
it.skip('check in process node', (done) => {}) | ||
|
||
it('stop node', (done) => { | ||
node.goOffline(done) | ||
}) | ||
}) | ||
|
||
describe('5 connected nodes (TCP)', () => {}) | ||
describe('10 connected nodes (TCP)', () => {}) | ||
describe('20 connected nodes (TCP)', () => {}) | ||
describe('20 connected nodes (TCP+WebSockets)', () => {}) | ||
}) |
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,55 @@ | ||
#! /usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const expect = require('chai').expect | ||
|
||
const IPFS = require('../../src/core') | ||
const createTempRepo = require('./temp-repo') | ||
|
||
function setAddresses (repo, callback) { | ||
repo.config.get((err, config) => { | ||
expect(err).to.not.exist | ||
config.Addresses = { | ||
Swarm: [ | ||
'/ip4/127.0.0.1/tcp/0' | ||
], | ||
API: '', | ||
Gateway: '' | ||
} | ||
|
||
repo.config.set(config, callback) | ||
}) | ||
} | ||
|
||
function createTempNode (callback) { | ||
const repo = createTempRepo() | ||
const ipfs = new IPFS(repo) | ||
|
||
ipfs.init({ emptyRepo: true }, (err) => { | ||
expect(err).to.not.exist | ||
setAddresses(repo, (err) => { | ||
expect(err).to.not.exist | ||
|
||
ipfs.load((err) => { | ||
expect(err).to.not.exist | ||
callback(null, ipfs) | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
createTempNode((err, ipfs) => { | ||
expect(err).to.not.exist | ||
ipfs.goOnline(() => { | ||
ipfs.id((err, id) => { | ||
expect(err).to.not.exist | ||
|
||
ipfs._libp2pNode.handle('/echo/1.0.0', (conn) => { | ||
conn.pipe(conn) | ||
}) | ||
|
||
console.log(JSON.stringify(id)) | ||
}) | ||
}) | ||
}) |
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,28 @@ | ||
'use strict' | ||
|
||
const spawn = require('child_process').spawn | ||
const path = require('path') | ||
const newLineParser = require('new-line') | ||
|
||
exports = module.exports | ||
|
||
exports.spawnNode = (transports, callback) => { | ||
const filePath = path.join(__dirname, './ipfs-node.js') | ||
const nodeProc = spawn(filePath, []) | ||
|
||
let count = 0 | ||
const nls = newLineParser() | ||
|
||
nodeProc.stdout.pipe(nls) | ||
|
||
nls.on('line', (data) => { | ||
if (count++ === 0) { return } | ||
const nodeInfo = JSON.parse(data.toString()) | ||
callback(null, { | ||
nodeInfo: nodeInfo, | ||
nodeProc: nodeProc, | ||
sigterm: () => {}, | ||
sigkill: () => { nodeProc.kill('SIGKILL') } | ||
}) | ||
}) | ||
} |
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 |
---|---|---|
|
@@ -41,4 +41,5 @@ function createTempNode (num, callback) { | |
}) | ||
}) | ||
} | ||
|
||
module.exports = createTempNode |
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