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

chore: change interface tests to async node creation #2625

Merged
merged 12 commits into from
Dec 10, 2019
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
52 changes: 18 additions & 34 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict'

const IPFSFactory = require('ipfsd-ctl')
const parallel = require('async/parallel')
const MockPreloadNode = require('./test/utils/mock-preload-node')
const EchoServer = require('interface-ipfs-core/src/utils/echo-http-server')
const callbackify = require('callbackify')

const ipfsdServer = IPFSFactory.createServer()
const preloadNode = MockPreloadNode.createNode()
Expand All @@ -29,40 +27,26 @@ module.exports = {
},
hooks: {
node: {
pre: (cb) => {
parallel([
(cb) => callbackify(preloadNode.start)(cb),
(cb) => echoServer.start(cb)
], cb)
},
post: (cb) => {
parallel([
(cb) => callbackify(preloadNode.stop)(cb),
(cb) => echoServer.stop(cb)
], cb)
}
pre: () => Promise.all([
preloadNode.start(),
echoServer.start()
]),
post: () => Promise.all([
preloadNode.stop(),
echoServer.stop()
])
},
browser: {
pre: (cb) => {
parallel([
(cb) => {
ipfsdServer.start()
cb()
},
(cb) => callbackify(preloadNode.start)(cb),
(cb) => echoServer.start(cb)
], cb)
},
post: (cb) => {
parallel([
(cb) => {
ipfsdServer.stop()
cb()
},
(cb) => callbackify(preloadNode.stop)(cb),
(cb) => echoServer.stop(cb)
], cb)
}
pre: () => Promise.all([
ipfsdServer.start(),
preloadNode.start(),
echoServer.start()
]),
post: () => Promise.all([
ipfsdServer.stop(),
preloadNode.stop(),
echoServer.stop()
])
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"p-iteration": "^1.1.8",
"p-queue": "^6.1.0",
"peer-book": "^0.9.1",
"peer-id": "^0.12.2",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"pretty-bytes": "^5.3.0",
"progress": "^2.0.1",
Expand Down Expand Up @@ -205,7 +205,7 @@
"execa": "^3.0.0",
"form-data": "^3.0.0",
"hat": "0.0.3",
"interface-ipfs-core": "^0.121.0",
"interface-ipfs-core": "^0.124.1",
"ipfs-interop": "^0.1.1",
"ipfsd-ctl": "^0.47.2",
"libp2p-websocket-star": "~0.10.2",
Expand Down
3 changes: 2 additions & 1 deletion src/core/components/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ module.exports = function bootstrap (self) {
throw invalidMultiaddrError(multiaddr)
}

let res = []
const config = await self._repo.config.get()
if (args.all) {
res = config.Bootstrap
config.Bootstrap = []
} else {
config.Bootstrap = config.Bootstrap.filter((mh) => mh !== multiaddr)
}

await self._repo.config.set(config)

const res = []
if (!args.all && multiaddr) {
res.push(multiaddr)
}
Expand Down
10 changes: 6 additions & 4 deletions test/cli/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ describe('bootstrap', () => runOnAndOff((thing) => {
it('rm all bootstrap nodes', async function () {
this.timeout(40 * 1000)

const out = await ipfs('bootstrap rm --all')
expect(out).to.equal('')
const outListBefore = await ipfs('bootstrap list')

const out2 = await ipfs('bootstrap list')
expect(out2).to.equal('')
const outRm = await ipfs('bootstrap rm --all')
expect(outRm).to.equal(outListBefore)

const outListAfter = await ipfs('bootstrap list')
expect(outListAfter).to.equal('')
})
}))
18 changes: 8 additions & 10 deletions test/core/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const isNode = require('detect-node')
describe('interface-ipfs-core tests', function () {
this.timeout(20 * 1000)

const defaultCommonFactory = CommonFactory.create()
const defaultCommonFactory = CommonFactory.createAsync()

tests.bitswap(defaultCommonFactory, { skip: !isNode })

Expand All @@ -20,7 +20,7 @@ describe('interface-ipfs-core tests', function () {

tests.dag(defaultCommonFactory)

tests.dht(CommonFactory.create({
tests.dht(CommonFactory.createAsync({
spawnOptions: {
config: {
Bootstrap: [],
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('interface-ipfs-core tests', function () {

tests.filesMFS(defaultCommonFactory)

tests.key(CommonFactory.create({
tests.key(CommonFactory.createAsync({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software'],
initOptions: { bits: 512 },
Expand All @@ -71,21 +71,19 @@ describe('interface-ipfs-core tests', function () {
}
}))

tests.miscellaneous(CommonFactory.create({
// No need to stop, because the test suite does a 'stop' test.
createTeardown: () => cb => cb(),
tests.miscellaneous(CommonFactory.createAsync({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software', '--offline']
}
}))

tests.name(CommonFactory.create({
tests.name(CommonFactory.createAsync({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software', '--offline']
}
}))

tests.namePubsub(CommonFactory.create({
tests.namePubsub(CommonFactory.createAsync({
spawnOptions: {
args: ['--enable-namesys-pubsub'],
initOptions: { bits: 1024 },
Expand Down Expand Up @@ -120,7 +118,7 @@ describe('interface-ipfs-core tests', function () {
}
})

tests.pubsub(CommonFactory.create({
tests.pubsub(CommonFactory.createAsync({
spawnOptions: {
initOptions: { bits: 512 }
}
Expand All @@ -134,5 +132,5 @@ describe('interface-ipfs-core tests', function () {

tests.stats(defaultCommonFactory)

tests.swarm(CommonFactory.createAsync(), { skip: !isNode })
tests.swarm(defaultCommonFactory, { skip: !isNode })
})
2 changes: 1 addition & 1 deletion test/http-api/inject/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = (http) => {
})

expect(res.statusCode).to.be.eql(200)
expect(res.result.Peers).to.be.eql([])
expect(res.result.Peers).to.be.eql(defaultList)
})
})
}
16 changes: 7 additions & 9 deletions test/http-api/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CommonFactory = require('../utils/interface-common-factory')
const path = require('path')

describe('interface-ipfs-core over ipfs-http-client tests', () => {
const defaultCommonFactory = CommonFactory.create({
const defaultCommonFactory = CommonFactory.createAsync({
factoryOptions: { exec: path.resolve(`${__dirname}/../../src/cli/bin.js`) }
})

Expand All @@ -28,7 +28,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
}]
})

tests.dht(CommonFactory.create({
tests.dht(CommonFactory.createAsync({
spawnOptions: {
initOptions: { bits: 512 },
config: {
Expand All @@ -54,7 +54,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {

tests.filesMFS(defaultCommonFactory)

tests.key(CommonFactory.create({
tests.key(CommonFactory.createAsync({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software'],
initOptions: { bits: 512 },
Expand All @@ -73,21 +73,19 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {
}
}))

tests.miscellaneous(CommonFactory.create({
// No need to stop, because the test suite does a 'stop' test.
createTeardown: () => cb => cb(),
tests.miscellaneous(CommonFactory.createAsync({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software', '--offline']
}
}))

tests.name(CommonFactory.create({
tests.name(CommonFactory.createAsync({
spawnOptions: {
args: ['--pass ipfs-is-awesome-software', '--offline']
}
}))

tests.namePubsub(CommonFactory.create({
tests.namePubsub(CommonFactory.createAsync({
spawnOptions: {
args: ['--enable-namesys-pubsub'],
initOptions: { bits: 1024 },
Expand Down Expand Up @@ -118,7 +116,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', () => {

tests.ping(defaultCommonFactory)

tests.pubsub(CommonFactory.create({
tests.pubsub(CommonFactory.createAsync({
spawnOptions: {
initOptions: { bits: 512 }
}
Expand Down
41 changes: 24 additions & 17 deletions test/utils/interface-common-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const callbackify = require('callbackify')
const mergeOptions = require('merge-options')
const IPFS = require('../../src')

const DEFAULT_FACTORY_OPTIONS = {
type: 'proc',
exec: IPFS
}

function createFactory (options) {
options = options || {}

options.factoryOptions = options.factoryOptions || { type: 'proc', exec: IPFS }
options.factoryOptions = options.factoryOptions || { ...DEFAULT_FACTORY_OPTIONS }
options.spawnOptions = mergeOptions({
initOptions: { bits: 512 },
config: {
Expand Down Expand Up @@ -68,25 +73,24 @@ function createFactory (options) {
}
}

function createAsync (createFactoryOptions = {}, createSpawnOptions = {}) {
function createAsync (options = {}) {
return () => {
const nodes = []
const setup = async (factoryOptions = {}, spawnOptions = {}) => {
factoryOptions = mergeOptions(
{
type: 'proc',
exec: IPFS
},
factoryOptions,
createFactoryOptions
const setup = async (setupOptions = {}) => {
options.factoryOptions = mergeOptions(
options.factoryOptions ? {} : { ...DEFAULT_FACTORY_OPTIONS },
setupOptions.factoryOptions,
options.factoryOptions
)

// When not an in proc daemon use the http-client js-ipfs depends on, not the one from ipfsd-ctl
if (factoryOptions.type !== 'proc') {
factoryOptions.IpfsClient = factoryOptions.IpfsClient || ipfsClient
if (options.factoryOptions.type !== 'proc') {
options.factoryOptions.IpfsClient = options.factoryOptions.IpfsClient || ipfsClient
}

const ipfsFactory = IPFSFactory.create(factoryOptions)
const node = await ipfsFactory.spawn(mergeOptions(
const ipfsFactory = IPFSFactory.create(options.factoryOptions)

options.spawnOptions = mergeOptions(
{
config: {
Bootstrap: [],
Expand All @@ -101,9 +105,12 @@ function createAsync (createFactoryOptions = {}, createSpawnOptions = {}) {
},
preload: { enabled: false }
},
spawnOptions,
createSpawnOptions
))
setupOptions.spawnOptions,
options.spawnOptions
)

const node = await ipfsFactory.spawn(options.spawnOptions)

nodes.push(node)

const id = await node.api.id()
Expand Down