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
Merged
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
38 changes: 10 additions & 28 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
'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
}],
browserNoActivityTimeout: 100 * 1000,
singleRun: true
},
hooks: {
pre: start,
post: stop
browser: {
pre: server.start.bind(server),
post: server.stop.bind(server)
}
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"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:webworker": "aegir test -t webworker --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 +71,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
56 changes: 40 additions & 16 deletions test/cli/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ 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 IPFS = require('../../src')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ type: 'js' })

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 ipfsdA
let ipfsdB
let cli
let httpApi

Expand All @@ -28,26 +40,38 @@ describe('pubsub', function () {
before(function (done) {
this.timeout(60 * 1000)

instanceFactory = new InstanceFactory()
instanceFactory.spawnNode((err, _node) => {
expect(err).to.not.exist()
node = _node
done()
})
DaemonFactory
.create({ type: 'proc' })
.spawn({
exec: IPFS,
config,
args: ['--enable-pubsub-experiment']
}, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsdA = _ipfsd
node = _ipfsd.api
done()
})
})

after((done) => instanceFactory.dismantle(done))
after((done) => ipfsdB.stop(done))

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

after((done) => daemonFactory.dismantle(done))
after((done) => ipfsdA.stop(done))
after((done) => ipfsdB.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({ type: 'js' })

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({ exec: `./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({ exec: `./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
93 changes: 58 additions & 35 deletions test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ 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 DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ type: 'js' })

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

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

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

function addNode (num, inProcNode, callback) {
num = leftPad(num, 3, 0)

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

connectNodes(remoteNode, inProcNode, (err) => callback(err, remoteNode))
let nodes = []

function addNode (inProcNode, callback) {
df.spawn({
exec: `./src/cli/bin.js`,
config: {
Addresses: {
Swarm: [`/ip4/127.0.0.1/tcp/0/ws`]
},
Discovery: {
MDNS: {
Enabled: false
}
},
Bootstrap: []
}
}, (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,23 +97,20 @@ describe('bitswap', function () {
beforeEach(function (done) {
this.timeout(60 * 1000)

let options = {
repo: createTempRepo(),
config: {
Addresses: {
Swarm: []
},
Discovery: {
MDNS: {
Enabled: false
}
},
Bootstrap: []
}
let config = {
Addresses: {
Swarm: []
},
Discovery: {
MDNS: {
Enabled: false
}
},
Bootstrap: []
}

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

inProcNode = new IPFS(options)
inProcNode.on('ready', () => done())
dfProc.spawn({ exec: IPFS, 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 +163,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 +174,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 +216,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 +270,7 @@ describe('bitswap', function () {

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

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