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

feat: reworking tests with new ipfsd-ctl #1167

Merged
merged 12 commits into from
Jan 24, 2018
37 changes: 9 additions & 28 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
'use strict'

const parallel = require('async/parallel')
const ads = require('./test/utils/another-daemon-spawner')
const js = ads.spawnJsNode
const stop = ads.stopNodes

/*
* spawns a daemon with ports numbers starting in 10 and ending in `num`
*/
function start (done) {
const base = '/ip4/127.0.0.1/tcp'
if (!process.env.IPFS_TEST) {
parallel([
(cb) => js([`${base}/10007`, `${base}/20007/ws`], true, 31007, 32007, cb),
(cb) => js([`${base}/10008`, `${base}/20008/ws`], true, 31008, 32008, cb),
(cb) => js([`${base}/10012`, `${base}/20012/ws`], true, 31012, 32012, cb),
(cb) => js([`${base}/10013`, `${base}/20013/ws`], true, 31013, 32013, cb),
(cb) => js([`${base}/10014`, `${base}/20014/ws`], true, 31014, 32014, cb),
(cb) => js([`${base}/10015`, `${base}/20015/ws`], true, 31015, 32015, cb)
], done)
} else if (process.env.IPFS_TEST === 'bootstrapers') {
done()
}
}
const createServer = require('ipfsd-ctl').createServer

const server = createServer()
module.exports = {
karma: {
files: [{
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',
watched: false,
served: true,
included: false,
singleRun: false
}]
included: false
}],
singleRun: true
},
hooks: {
pre: start,
post: stop
browser: {
pre: server.start.bind(server),
post: server.stop.bind(server)
}
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build": "aegir build",
"test": "aegir test -t node -t browser -t webworker --no-cors",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser -t webworker --no-cors",
"test:browser": "aegir test -t browser --no-cors",
"test:node:core": "aegir test -t node -f test/core/**.js",
"test:node:http": "aegir test -t node -f test/http-api/index.js",
"test:node:gateway": "aegir test -t node -f test/gateway/index.js",
Expand Down Expand Up @@ -70,8 +70,10 @@
"execa": "^0.9.0",
"expose-loader": "^0.7.4",
"form-data": "^2.3.1",
"go-ipfs-dep": "^0.4.13",
"hat": "0.0.3",
"interface-ipfs-core": "~0.40.0",
"interface-ipfs-core": "~0.41.0",
"ipfsd-ctl": "^0.27.0",
"left-pad": "^1.2.0",
"lodash": "^4.17.4",
"mocha": "^4.1.0",
Expand Down
62 changes: 48 additions & 14 deletions test/cli/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,80 @@ const expect = chai.expect
chai.use(dirtyChai)
const delay = require('delay')
const series = require('async/series')
const InstanceFactory = require('../utils/ipfs-factory-instance')
const DaemonFactory = require('../utils/ipfs-factory-daemon')
const ipfsExec = require('../utils/ipfs-exec')
const createRepo = require('../utils/create-repo-nodejs')
const IPFS = require('../../src')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create()

const config = {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled:
false
}
}
}

describe('pubsub', function () {
this.timeout(40 * 1000)
this.timeout(80 * 1000)

let instanceFactory
let daemonFactory
let node
let ipfsd
let cli
let httpApi

const topicA = 'nonscentsA'
const topicB = 'nonscentsB'
const topicC = 'nonscentsC'

let repo = createRepo()
before(function (done) {
this.timeout(60 * 1000)

instanceFactory = new InstanceFactory()
instanceFactory.spawnNode((err, _node) => {
expect(err).to.not.exist()
node = _node
node = new IPFS({
repo: createRepo(),
init: { bits: 1024 },
EXPERIMENTAL: {
pubsub: true
},
config
})

node.once('ready', () => {
done()
})

node.once('error', (err) => {
done(err)
})
})

after((done) => instanceFactory.dismantle(done))
after((done) => {
node.stop((err) => {
expect(err).to.not.exist()
repo.teardown(done)
})
})

before((done) => {
daemonFactory = new DaemonFactory()
daemonFactory.spawnNode((err, _node) => {
df.spawn({
type: 'js',
args: ['--enable-pubsub-experiment'],
exec: `${process.cwd()}/src/cli/bin.js`,
config
}, (err, _node) => {
expect(err).to.not.exist()
httpApi = _node
httpApi = _node.api
ipfsd = _node
httpApi.repoPath = ipfsd.repoPath
done()
})
})

after((done) => daemonFactory.dismantle(done))
after((done) => ipfsd.stop(done))

before((done) => {
cli = ipfsExec(httpApi.repoPath)
Expand Down
30 changes: 22 additions & 8 deletions test/cli/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,56 @@ const expect = chai.expect
chai.use(dirtyChai)
const series = require('async/series')
const ipfsExec = require('../utils/ipfs-exec')
const Factory = require('../utils/ipfs-factory-daemon')

const parallel = require('async/parallel')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create()

const config = {
Bootstrap: [],
Discovery: {
MDNS: {
Enabled:
false
}
}
}

describe('swarm', () => {
let factory
let bMultiaddr
let ipfsA

let nodes = []
before(function (done) {
// CI takes longer to instantiate the daemon, so we need to increase the
// timeout for the before step
this.timeout(80 * 1000)

factory = new Factory()

series([
(cb) => {
factory.spawnNode((err, node) => {
df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => {
expect(err).to.not.exist()
ipfsA = ipfsExec(node.repoPath)
nodes.push(node)
cb()
})
},
(cb) => {
factory.spawnNode((err, node) => {
df.spawn({ type: 'js', exec: `${process.cwd()}/src/cli/bin.js`, config }, (err, node) => {
expect(err).to.not.exist()
node.id((err, id) => {
node.api.id((err, id) => {
expect(err).to.not.exist()
bMultiaddr = id.addresses[0]
nodes.push(node)
cb()
})
})
}
], done)
})

after((done) => factory.dismantle(done))
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))

describe('daemon on (through http-api)', function () {
this.timeout(60 * 1000)
Expand Down
68 changes: 43 additions & 25 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ const _ = require('lodash')
const series = require('async/series')
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const leftPad = require('left-pad')
const Block = require('ipfs-block')
const API = require('ipfs-api')
const multiaddr = require('multiaddr')
const isNode = require('detect-node')
const multihashing = require('multihashing-async')
const CID = require('cids')

const IPFS = require('../../src/core')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ type: 'js', exec: `./src/cli/bin.js` })

const dfProc = DaemonFactory.create({ type: 'proc', exec: IPFS })

// This gets replaced by '../utils/create-repo-browser.js' in the browser
const createTempRepo = require('../utils/create-repo-nodejs.js')

const IPFS = require('../../src/core')

function makeBlock (callback) {
const d = Buffer.from(`IPFS is awesome ${Math.random()}`)

Expand Down Expand Up @@ -63,13 +66,20 @@ function connectNodes (remoteNode, inProcNode, callback) {
], callback)
}

function addNode (num, inProcNode, callback) {
num = leftPad(num, 3, 0)
let nodes = []

const apiUrl = `/ip4/127.0.0.1/tcp/31${num}`
const remoteNode = new API(apiUrl)

connectNodes(remoteNode, inProcNode, (err) => callback(err, remoteNode))
function addNode (inProcNode, callback) {
df.spawn({
config: {
Addresses: {
Swarm: [`/ip4/127.0.0.1/tcp/0/ws`]
}
}
}, (err, ipfsd) => {
expect(err).to.not.exist()
nodes.push(ipfsd)
connectNodes(ipfsd.api, inProcNode, (err) => callback(err, ipfsd.api))
})
}

describe('bitswap', function () {
Expand All @@ -80,8 +90,7 @@ describe('bitswap', function () {
beforeEach(function (done) {
this.timeout(60 * 1000)

let options = {
repo: createTempRepo(),
let config = {
config: {
Addresses: {
Swarm: []
Expand All @@ -96,7 +105,7 @@ describe('bitswap', function () {
}

if (isNode) {
options = Object.assign(options, {
config = Object.assign(config, {
config: {
Addresses: {
Swarm: ['/ip4/127.0.0.1/tcp/0']
Expand All @@ -105,25 +114,34 @@ describe('bitswap', function () {
})
}

inProcNode = new IPFS(options)
inProcNode.on('ready', () => done())
dfProc.spawn({ config }, (err, _ipfsd) => {
expect(err).to.not.exist()
nodes.push(_ipfsd)
inProcNode = _ipfsd.api
done()
})
})

afterEach(function (done) {
this.timeout(60 * 1000)
setTimeout(() => inProcNode.stop(() => done()), 500)
this.timeout(80 * 1000)
const tasks = nodes.map((node) => (cb) => node.stop(cb))
parallel(tasks, (err) => {
expect(err).to.not.exist()
nodes = []
done()
})
})

describe('transfer a block between', () => {
it('2 peers', function (done) {
this.timeout(40 * 1000)
this.timeout(80 * 1000)

let remoteNode
let block
waterfall([
(cb) => parallel([
(cb) => makeBlock(cb),
(cb) => addNode(13, inProcNode, cb)
(cb) => addNode(inProcNode, cb)
], cb),
(res, cb) => {
block = res[0]
Expand All @@ -140,7 +158,7 @@ describe('bitswap', function () {
})

it('3 peers', function (done) {
this.timeout(60 * 1000)
this.timeout(80 * 1000)

let blocks
const remoteNodes = []
Expand All @@ -151,11 +169,11 @@ describe('bitswap', function () {
blocks = _blocks
cb()
}),
(cb) => addNode(8, inProcNode, (err, _ipfs) => {
(cb) => addNode(inProcNode, (err, _ipfs) => {
remoteNodes.push(_ipfs)
cb(err)
}),
(cb) => addNode(7, inProcNode, (err, _ipfs) => {
(cb) => addNode(inProcNode, (err, _ipfs) => {
remoteNodes.push(_ipfs)
cb(err)
}),
Expand Down Expand Up @@ -193,10 +211,10 @@ describe('bitswap', function () {

waterfall([
// 0. Start node
(cb) => addNode(12, inProcNode, cb),
(cb) => addNode(inProcNode, cb),
// 1. Add file to tmp instance
(remote, cb) => {
remote.files.add([{path: 'awesome.txt', content: file}], cb)
remote.files.add([{ path: 'awesome.txt', content: file }], cb)
},
// 2. Request file from local instance
(filesAdded, cb) => inProcNode.files.cat(filesAdded[0].hash, cb)
Expand Down Expand Up @@ -247,7 +265,7 @@ describe('bitswap', function () {

describe('while online', () => {
before(function (done) {
this.timeout(40 * 1000)
this.timeout(80 * 1000)

node.start(() => done())
})
Expand Down
Loading