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

Commit bbcce34

Browse files
Pedro Santosachingbrain
Pedro Santos
authored andcommitted
chore: change interface tests to async node creation (#2625)
* chore: change interface tests to async node creation * fix: bootstrap rm return value when all option is set (#2626) * chore: update interface-ipfs-core dep * chore: code review changes * chore: link interface core tests dependency to new branch * chore: update interface-core dep * refactor: aegir pre and post hooks on both node and browser * chore: restore interface tests branch * chore: control peer id version * chore: use version of http client with controlled peer id version * fix: use regular version of http client * chore: update interface test version
1 parent 79db03b commit bbcce34

File tree

8 files changed

+68
-78
lines changed

8 files changed

+68
-78
lines changed

.aegir.js

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict'
22

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

97
const ipfsdServer = IPFSFactory.createServer()
108
const preloadNode = MockPreloadNode.createNode()
@@ -29,40 +27,26 @@ module.exports = {
2927
},
3028
hooks: {
3129
node: {
32-
pre: (cb) => {
33-
parallel([
34-
(cb) => callbackify(preloadNode.start)(cb),
35-
(cb) => echoServer.start(cb)
36-
], cb)
37-
},
38-
post: (cb) => {
39-
parallel([
40-
(cb) => callbackify(preloadNode.stop)(cb),
41-
(cb) => echoServer.stop(cb)
42-
], cb)
43-
}
30+
pre: () => Promise.all([
31+
preloadNode.start(),
32+
echoServer.start()
33+
]),
34+
post: () => Promise.all([
35+
preloadNode.stop(),
36+
echoServer.stop()
37+
])
4438
},
4539
browser: {
46-
pre: (cb) => {
47-
parallel([
48-
(cb) => {
49-
ipfsdServer.start()
50-
cb()
51-
},
52-
(cb) => callbackify(preloadNode.start)(cb),
53-
(cb) => echoServer.start(cb)
54-
], cb)
55-
},
56-
post: (cb) => {
57-
parallel([
58-
(cb) => {
59-
ipfsdServer.stop()
60-
cb()
61-
},
62-
(cb) => callbackify(preloadNode.stop)(cb),
63-
(cb) => echoServer.stop(cb)
64-
], cb)
65-
}
40+
pre: () => Promise.all([
41+
ipfsdServer.start(),
42+
preloadNode.start(),
43+
echoServer.start()
44+
]),
45+
post: () => Promise.all([
46+
ipfsdServer.stop(),
47+
preloadNode.stop(),
48+
echoServer.stop()
49+
])
6650
}
6751
}
6852
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"p-iteration": "^1.1.8",
163163
"p-queue": "^6.1.0",
164164
"peer-book": "^0.9.1",
165-
"peer-id": "^0.12.2",
165+
"peer-id": "~0.12.2",
166166
"peer-info": "~0.15.1",
167167
"pretty-bytes": "^5.3.0",
168168
"progress": "^2.0.1",
@@ -205,7 +205,7 @@
205205
"execa": "^3.0.0",
206206
"form-data": "^3.0.0",
207207
"hat": "0.0.3",
208-
"interface-ipfs-core": "^0.121.0",
208+
"interface-ipfs-core": "^0.124.1",
209209
"ipfs-interop": "^0.1.1",
210210
"ipfsd-ctl": "^0.47.2",
211211
"libp2p-websocket-star": "~0.10.2",

src/core/components/bootstrap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ module.exports = function bootstrap (self) {
4545
throw invalidMultiaddrError(multiaddr)
4646
}
4747

48+
let res = []
4849
const config = await self._repo.config.get()
4950
if (args.all) {
51+
res = config.Bootstrap
5052
config.Bootstrap = []
5153
} else {
5254
config.Bootstrap = config.Bootstrap.filter((mh) => mh !== multiaddr)
5355
}
5456

5557
await self._repo.config.set(config)
5658

57-
const res = []
5859
if (!args.all && multiaddr) {
5960
res.push(multiaddr)
6061
}

test/cli/bootstrap.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ describe('bootstrap', () => runOnAndOff((thing) => {
9494
it('rm all bootstrap nodes', async function () {
9595
this.timeout(40 * 1000)
9696

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

100-
const out2 = await ipfs('bootstrap list')
101-
expect(out2).to.equal('')
99+
const outRm = await ipfs('bootstrap rm --all')
100+
expect(outRm).to.equal(outListBefore)
101+
102+
const outListAfter = await ipfs('bootstrap list')
103+
expect(outListAfter).to.equal('')
102104
})
103105
}))

test/core/interface.spec.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const isNode = require('detect-node')
88
describe('interface-ipfs-core tests', function () {
99
this.timeout(20 * 1000)
1010

11-
const defaultCommonFactory = CommonFactory.create()
11+
const defaultCommonFactory = CommonFactory.createAsync()
1212

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

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

2121
tests.dag(defaultCommonFactory)
2222

23-
tests.dht(CommonFactory.create({
23+
tests.dht(CommonFactory.createAsync({
2424
spawnOptions: {
2525
config: {
2626
Bootstrap: [],
@@ -53,7 +53,7 @@ describe('interface-ipfs-core tests', function () {
5353

5454
tests.filesMFS(defaultCommonFactory)
5555

56-
tests.key(CommonFactory.create({
56+
tests.key(CommonFactory.createAsync({
5757
spawnOptions: {
5858
args: ['--pass ipfs-is-awesome-software'],
5959
initOptions: { bits: 512 },
@@ -71,21 +71,19 @@ describe('interface-ipfs-core tests', function () {
7171
}
7272
}))
7373

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

82-
tests.name(CommonFactory.create({
80+
tests.name(CommonFactory.createAsync({
8381
spawnOptions: {
8482
args: ['--pass ipfs-is-awesome-software', '--offline']
8583
}
8684
}))
8785

88-
tests.namePubsub(CommonFactory.create({
86+
tests.namePubsub(CommonFactory.createAsync({
8987
spawnOptions: {
9088
args: ['--enable-namesys-pubsub'],
9189
initOptions: { bits: 1024 },
@@ -120,7 +118,7 @@ describe('interface-ipfs-core tests', function () {
120118
}
121119
})
122120

123-
tests.pubsub(CommonFactory.create({
121+
tests.pubsub(CommonFactory.createAsync({
124122
spawnOptions: {
125123
initOptions: { bits: 512 }
126124
}
@@ -134,5 +132,5 @@ describe('interface-ipfs-core tests', function () {
134132

135133
tests.stats(defaultCommonFactory)
136134

137-
tests.swarm(CommonFactory.createAsync(), { skip: !isNode })
135+
tests.swarm(defaultCommonFactory, { skip: !isNode })
138136
})

test/http-api/inject/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = (http) => {
8383
})
8484

8585
expect(res.statusCode).to.be.eql(200)
86-
expect(res.result.Peers).to.be.eql([])
86+
expect(res.result.Peers).to.be.eql(defaultList)
8787
})
8888
})
8989
}

test/http-api/interface.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const CommonFactory = require('../utils/interface-common-factory')
66
const path = require('path')
77

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

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

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

5555
tests.filesMFS(defaultCommonFactory)
5656

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

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

84-
tests.name(CommonFactory.create({
82+
tests.name(CommonFactory.createAsync({
8583
spawnOptions: {
8684
args: ['--pass ipfs-is-awesome-software', '--offline']
8785
}
8886
}))
8987

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

119117
tests.ping(defaultCommonFactory)
120118

121-
tests.pubsub(CommonFactory.create({
119+
tests.pubsub(CommonFactory.createAsync({
122120
spawnOptions: {
123121
initOptions: { bits: 512 }
124122
}

test/utils/interface-common-factory.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ const callbackify = require('callbackify')
88
const mergeOptions = require('merge-options')
99
const IPFS = require('../../src')
1010

11+
const DEFAULT_FACTORY_OPTIONS = {
12+
type: 'proc',
13+
exec: IPFS
14+
}
15+
1116
function createFactory (options) {
1217
options = options || {}
1318

14-
options.factoryOptions = options.factoryOptions || { type: 'proc', exec: IPFS }
19+
options.factoryOptions = options.factoryOptions || { ...DEFAULT_FACTORY_OPTIONS }
1520
options.spawnOptions = mergeOptions({
1621
initOptions: { bits: 512 },
1722
config: {
@@ -68,25 +73,24 @@ function createFactory (options) {
6873
}
6974
}
7075

71-
function createAsync (createFactoryOptions = {}, createSpawnOptions = {}) {
76+
function createAsync (options = {}) {
7277
return () => {
7378
const nodes = []
74-
const setup = async (factoryOptions = {}, spawnOptions = {}) => {
75-
factoryOptions = mergeOptions(
76-
{
77-
type: 'proc',
78-
exec: IPFS
79-
},
80-
factoryOptions,
81-
createFactoryOptions
79+
const setup = async (setupOptions = {}) => {
80+
options.factoryOptions = mergeOptions(
81+
options.factoryOptions ? {} : { ...DEFAULT_FACTORY_OPTIONS },
82+
setupOptions.factoryOptions,
83+
options.factoryOptions
8284
)
85+
8386
// When not an in proc daemon use the http-client js-ipfs depends on, not the one from ipfsd-ctl
84-
if (factoryOptions.type !== 'proc') {
85-
factoryOptions.IpfsClient = factoryOptions.IpfsClient || ipfsClient
87+
if (options.factoryOptions.type !== 'proc') {
88+
options.factoryOptions.IpfsClient = options.factoryOptions.IpfsClient || ipfsClient
8689
}
8790

88-
const ipfsFactory = IPFSFactory.create(factoryOptions)
89-
const node = await ipfsFactory.spawn(mergeOptions(
91+
const ipfsFactory = IPFSFactory.create(options.factoryOptions)
92+
93+
options.spawnOptions = mergeOptions(
9094
{
9195
config: {
9296
Bootstrap: [],
@@ -101,9 +105,12 @@ function createAsync (createFactoryOptions = {}, createSpawnOptions = {}) {
101105
},
102106
preload: { enabled: false }
103107
},
104-
spawnOptions,
105-
createSpawnOptions
106-
))
108+
setupOptions.spawnOptions,
109+
options.spawnOptions
110+
)
111+
112+
const node = await ipfsFactory.spawn(options.spawnOptions)
113+
107114
nodes.push(node)
108115

109116
const id = await node.api.id()

0 commit comments

Comments
 (0)