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

Commit 7067953

Browse files
committed
tests: update ipfsd-ctl
This new version of ipfsd-ctl is using async/await instead of callbacks. Hence some rather mechanical changes are needed for tests.
1 parent 2c46f53 commit 7067953

35 files changed

+397
-615
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
"form-data": "^2.5.0",
191191
"hat": "0.0.3",
192192
"interface-ipfs-core": "^0.109.1",
193-
"ipfsd-ctl": "^0.43.0",
193+
"ipfsd-ctl": "^0.44.1",
194194
"libp2p-websocket-star": "~0.10.2",
195195
"ncp": "^2.0.0",
196196
"qs": "^6.5.2",

test/bootstrapers.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const chai = require('chai')
5-
const dirtyChai = require('dirty-chai')
6-
const expect = chai.expect
7-
chai.use(dirtyChai)
84
const IPFS = require('..')
95
const IPFSFactory = require('ipfsd-ctl')
106
const bootstrapList = require('../src/core/runtime/config-browser.js')().Bootstrap
@@ -17,25 +13,21 @@ const waitFor = require('./utils/wait-for')
1713
describe('Check that a js-ipfs node can indeed contact the bootstrappers', () => {
1814
let ipfsd
1915

20-
before(function (done) {
16+
before(async () => {
2117
this.timeout(30 * 1000)
2218

2319
const factory = IPFSFactory.create({ type: 'proc', exec: IPFS })
2420

25-
factory.spawn({
21+
ipfsd = await factory.spawn({
2622
config: {
2723
Addresses: {
2824
Swarm: []
2925
}
3026
}
31-
}, (err, node) => {
32-
expect(err).to.not.exist()
33-
ipfsd = node
34-
done()
3527
})
3628
})
3729

38-
after(done => ipfsd.stop(done))
30+
after(() => ipfsd.stop())
3931

4032
it('a node connects to bootstrappers', function (done) {
4133
this.timeout(2 * 60 * 1000)

test/cli/dht.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const dirtyChai = require('dirty-chai')
77
const expect = chai.expect
88
chai.use(dirtyChai)
99

10-
const series = require('async/series')
1110
const parallel = require('async/parallel')
1211
const path = require('path')
1312
const DaemonFactory = require('ipfsd-ctl')
@@ -41,24 +40,16 @@ describe.skip('dht', () => {
4140
let multiaddrB
4241

4342
// spawn daemons
44-
before(function (done) {
43+
before(async function () {
4544
this.timeout(80 * 1000)
46-
series([
47-
(cb) => df.spawn(daemonOpts, (err, _ipfsd) => {
48-
expect(err).to.not.exist()
4945

50-
ipfsA = ipfsExec(_ipfsd.repoPath)
51-
nodes.push(_ipfsd)
52-
cb()
53-
}),
54-
(cb) => df.spawn(daemonOpts, (err, _ipfsd) => {
55-
expect(err).to.not.exist()
46+
const ipfsdA = await df.spawn(daemonOpts)
47+
ipfsA = ipfsExec(ipfsdA.repoPath)
48+
nodes.push(ipfsdA)
5649

57-
ipfsB = ipfsExec(_ipfsd.repoPath)
58-
nodes.push(_ipfsd)
59-
cb()
60-
})
61-
], done)
50+
const ipfsdB = await df.spawn(daemonOpts)
51+
ipfsB = ipfsExec(ipfsdB.repoPath)
52+
nodes.push(ipfsdB)
6253
})
6354

6455
// get ids
@@ -88,7 +79,7 @@ describe.skip('dht', () => {
8879
nodes[0].api.swarm.connect(multiaddrB, done)
8980
})
9081

91-
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
82+
after(() => Promise.all(nodes.map((node) => node.stop())))
9283

9384
it('should be able to put a value to the dht and get it afterwards', function () {
9485
this.timeout(60 * 1000)

test/cli/name-pubsub.js

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,27 @@ const expect = chai.expect
88
chai.use(dirtyChai)
99
const path = require('path')
1010
const parallel = require('async/parallel')
11-
const series = require('async/series')
1211
const ipfsExec = require('../utils/ipfs-exec')
1312

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

17-
const spawnDaemon = (callback) => {
18-
df.spawn({
19-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
20-
args: ['--enable-namesys-pubsub'],
21-
initOptions: { bits: 512 },
22-
config: {
23-
Bootstrap: [],
24-
Discovery: {
25-
MDNS: {
26-
Enabled: false
27-
},
28-
webRTCStar: {
29-
Enabled: false
30-
}
16+
const spawnDaemon = () => df.spawn({
17+
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
18+
args: ['--enable-namesys-pubsub'],
19+
initOptions: { bits: 512 },
20+
config: {
21+
Bootstrap: [],
22+
Discovery: {
23+
MDNS: {
24+
Enabled: false
25+
},
26+
webRTCStar: {
27+
Enabled: false
3128
}
3229
}
33-
}, callback)
34-
}
30+
}
31+
})
3532

3633
describe('name-pubsub', () => {
3734
describe('enabled', () => {
@@ -43,29 +40,18 @@ describe('name-pubsub', () => {
4340
const nodes = []
4441

4542
// Spawn daemons
46-
before(function (done) {
43+
before(async function () {
4744
// CI takes longer to instantiate the daemon, so we need to increase the
4845
// timeout for the before step
4946
this.timeout(80 * 1000)
5047

51-
series([
52-
(cb) => {
53-
spawnDaemon((err, node) => {
54-
expect(err).to.not.exist()
55-
ipfsA = ipfsExec(node.repoPath)
56-
nodes.push(node)
57-
cb()
58-
})
59-
},
60-
(cb) => {
61-
spawnDaemon((err, node) => {
62-
expect(err).to.not.exist()
63-
ipfsB = ipfsExec(node.repoPath)
64-
nodes.push(node)
65-
cb()
66-
})
67-
}
68-
], done)
48+
const nodeA = await spawnDaemon()
49+
ipfsA = ipfsExec(nodeA.repoPath)
50+
nodes.push(nodeA)
51+
52+
const nodeB = await spawnDaemon()
53+
ipfsB = ipfsExec(nodeB.repoPath)
54+
nodes.push(nodeB)
6955
})
7056

7157
// Get node ids
@@ -97,7 +83,7 @@ describe('name-pubsub', () => {
9783
})
9884
})
9985

100-
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
86+
after(() => Promise.all(nodes.map((node) => node.stop())))
10187

10288
describe('pubsub commands', () => {
10389
it('should get enabled state of pubsub', function () {
@@ -166,27 +152,27 @@ describe('name-pubsub', () => {
166152

167153
describe('disabled', () => {
168154
let ipfsA
169-
const nodes = []
155+
let node
170156

171157
// Spawn daemons
172-
before(function (done) {
158+
before(async function () {
173159
// CI takes longer to instantiate the daemon, so we need to increase the
174160
// timeout for the before step
175161
this.timeout(80 * 1000)
176162

177-
df.spawn({
163+
node = await df.spawn({
178164
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
179165
config: {},
180166
initOptions: { bits: 512 }
181-
}, (err, node) => {
182-
expect(err).to.not.exist()
183-
ipfsA = ipfsExec(node.repoPath)
184-
nodes.push(node)
185-
done()
186167
})
168+
ipfsA = ipfsExec(node.repoPath)
187169
})
188170

189-
after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))
171+
after(() => {
172+
if (node) {
173+
return node.stop()
174+
}
175+
})
190176

191177
it('should get disabled state of pubsub', function () {
192178
return ipfsA('name pubsub state')

test/cli/ping.js

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
const chai = require('chai')
66
const dirtyChai = require('dirty-chai')
7-
const series = require('async/series')
87
const DaemonFactory = require('ipfsd-ctl')
98
const ipfsExec = require('../utils/ipfs-exec')
109
const path = require('path')
@@ -30,44 +29,29 @@ describe('ping', function () {
3029
let ipfsdBId
3130
let cli
3231

33-
before((done) => {
32+
before(async function () {
3433
this.timeout(60 * 1000)
35-
series([
36-
(cb) => {
37-
df.spawn({
38-
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
39-
config,
40-
initOptions: { bits: 512 }
41-
}, (err, _ipfsd) => {
42-
expect(err).to.not.exist()
43-
ipfsdB = _ipfsd
44-
cb()
45-
})
46-
},
47-
(cb) => {
48-
ipfsdB.api.id((err, peerInfo) => {
49-
expect(err).to.not.exist()
50-
ipfsdBId = peerInfo.id
51-
bMultiaddr = peerInfo.addresses[0]
52-
cb()
53-
})
54-
}
55-
], done)
34+
35+
ipfsdB = await df.spawn({
36+
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
37+
config,
38+
initOptions: { bits: 512 }
39+
})
40+
const peerInfo = await ipfsdB.api.id()
41+
ipfsdBId = peerInfo.id
42+
bMultiaddr = peerInfo.addresses[0]
5643
})
5744

58-
before(function (done) {
45+
before(async function () {
5946
this.timeout(60 * 1000)
6047

61-
df.spawn({
48+
ipfsdA = await df.spawn({
6249
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
6350
config,
64-
initoptions: { bits: 512 }
65-
}, (err, _ipfsd) => {
66-
expect(err).to.not.exist()
67-
ipfsdA = _ipfsd
68-
// Without DHT we need to have an already established connection
69-
ipfsdA.api.swarm.connect(bMultiaddr, done)
51+
initOptions: { bits: 512 }
7052
})
53+
// Without DHT we need to have an already established connection
54+
await ipfsdA.api.swarm.connect(bMultiaddr)
7155
})
7256

7357
before((done) => {
@@ -76,14 +60,15 @@ describe('ping', function () {
7660
done()
7761
})
7862

79-
after((done) => {
80-
if (!ipfsdA) return done()
81-
ipfsdA.stop(done)
63+
after(() => {
64+
if (ipfsdA) {
65+
return ipfsdA.stop()
66+
}
8267
})
83-
84-
after((done) => {
85-
if (!ipfsdB) return done()
86-
ipfsdB.stop(done)
68+
after(() => {
69+
if (ipfsdB) {
70+
return ipfsdB.stop()
71+
}
8772
})
8873

8974
it('ping host', (done) => {

test/cli/pubsub.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const ipfsExec = require('../utils/ipfs-exec')
1212
const IPFS = require('../../src')
1313
const path = require('path')
1414
const DaemonFactory = require('ipfsd-ctl')
15-
const df = DaemonFactory.create({ type: 'js' })
1615

1716
const config = {
1817
Bootstrap: [],
@@ -37,43 +36,47 @@ describe('pubsub', function () {
3736
const topicB = 'nonscentsB'
3837
const topicC = 'nonscentsC'
3938

40-
before(function (done) {
39+
before(async function () {
4140
this.timeout(60 * 1000)
4241

43-
DaemonFactory
44-
.create({ type: 'proc' })
45-
.spawn({
46-
exec: IPFS,
47-
initOptions: { bits: 512 },
48-
config,
49-
args: ['--enable-pubsub-experiment']
50-
}, (err, _ipfsd) => {
51-
expect(err).to.not.exist()
52-
ipfsdA = _ipfsd
53-
node = _ipfsd.api
54-
done()
55-
})
42+
const df = DaemonFactory.create({ type: 'proc' })
43+
ipfsdA = await df.spawn({
44+
exec: IPFS,
45+
initOptions: { bits: 512 },
46+
config,
47+
args: ['--enable-pubsub-experiment']
48+
})
49+
node = ipfsdA.api
5650
})
5751

58-
after((done) => ipfsdB.stop(done))
52+
after(() => {
53+
if (ipfsdB) {
54+
return ipfsdB.stop()
55+
}
56+
})
5957

60-
before((done) => {
61-
df.spawn({
58+
before(async () => {
59+
const df = DaemonFactory.create({ type: 'js' })
60+
ipfsdB = await df.spawn({
6261
initOptions: { bits: 512 },
6362
args: ['--enable-pubsub-experiment'],
6463
exec: path.resolve(`${__dirname}/../../src/cli/bin.js`),
6564
config
66-
}, (err, _ipfsd) => {
67-
expect(err).to.not.exist()
68-
httpApi = _ipfsd.api
69-
ipfsdB = _ipfsd
70-
httpApi.repoPath = ipfsdB.repoPath
71-
done()
7265
})
66+
httpApi = ipfsdB.api
67+
httpApi.repoPath = ipfsdB.repoPath
7368
})
7469

75-
after((done) => ipfsdA.stop(done))
76-
after((done) => ipfsdB.stop(done))
70+
after(() => {
71+
if (ipfsdA) {
72+
return ipfsdA.stop()
73+
}
74+
})
75+
after(() => {
76+
if (ipfsdB) {
77+
return ipfsdB.stop()
78+
}
79+
})
7780

7881
before((done) => {
7982
cli = ipfsExec(httpApi.repoPath)

0 commit comments

Comments
 (0)