Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

test: chaotic network tests #299

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"lodash": "^4.11.2",
"mocha": "^2.5.1",
"ncp": "^2.0.0",
"new-line": "^1.1.1",
"nexpect": "^0.5.0",
"pre-commit": "^1.1.2",
"rimraf": "^2.5.2",
Expand Down
2 changes: 0 additions & 2 deletions src/core/ipfs/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const mafmt = require('mafmt')
const OFFLINE_ERROR = require('../utils').OFFLINE_ERROR

module.exports = function libp2p (self) {
// NOTE: TODO CONSIDER/ CONSIDERING putting all of libp2p (start, stop, peerbook and so on) inside the libp2p object and reduce one layer

return {
start: (callback) => {
self._libp2pNode = new Libp2pNode(self._peerInfo)
Expand Down
78 changes: 78 additions & 0 deletions test/core/node-only/test-network-stress.js
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)', () => {})
})
55 changes: 55 additions & 0 deletions test/utils/ipfs-node.js
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))
})
})
})
28 changes: 28 additions & 0 deletions test/utils/spawn-ipfs-node.js
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') }
})
})
}
1 change: 1 addition & 0 deletions test/utils/temp-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ function createTempNode (num, callback) {
})
})
}

module.exports = createTempNode
6 changes: 3 additions & 3 deletions test/utils/temp-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

const IPFSRepo = require('ipfs-repo')
const clean = require('./clean')
const isNode = require('detect-node')

function createTempRepo () {
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8)
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 10)

let store
let teardown

const isNode = require('detect-node')
if (isNode) {
store = require('fs-blob-store')
teardown = (done) => {
Expand All @@ -36,7 +36,7 @@ function createTempRepo () {
})

repo.teardown = teardown

repo.path = repoPath
return repo
}

Expand Down