Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 49daf28

Browse files
committed
chore: refactor swarm tests
1 parent 9cdc041 commit 49daf28

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

src/swarm.js

+25-39
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ module.exports = (common) => {
6161
})
6262

6363
// for Identify to finish
64-
it('time', (done) => {
65-
setTimeout(done, 1500)
66-
})
64+
it('time', (done) => setTimeout(done, 1500))
6765

6866
describe('.peers', () => {
6967
beforeEach((done) => {
@@ -110,20 +108,23 @@ module.exports = (common) => {
110108
})
111109
})
112110

113-
const getConfig = (addresses) => {
114-
return {
115-
Addresses: {
116-
Swarm: addresses,
117-
API: '/ip4/127.0.0.1/tcp/0',
118-
Gateway: '/ip4/127.0.0.1/tcp/0'
111+
describe('Shows connected peers only once', () => {
112+
function getConfig (addrs) {
113+
addrs = Array.isArray(addrs) ? addrs : [addrs]
114+
115+
return {
116+
Addresses: {
117+
Swarm: addrs,
118+
API: '/ip4/127.0.0.1/tcp/0',
119+
Gateway: '/ip4/127.0.0.1/tcp/0'
120+
}
119121
}
120122
}
121-
}
122-
const getRepoPath = () => {
123-
return '/tmp/.ipfs-' + Math.random().toString().substring(2, 8)
124-
}
125123

126-
describe('Shows connected peers only once', () => {
124+
function getRepoPath () {
125+
return '/tmp/.ipfs-' + Math.random().toString().substring(2, 8) + Date.now()
126+
}
127+
127128
it('Connecting two peers with one address each', (done) => {
128129
let nodeA
129130
let nodeB
@@ -152,16 +153,8 @@ module.exports = (common) => {
152153
cb()
153154
})
154155
},
155-
(cb) => {
156-
nodeA.swarm.connect(nodeBAddress, (err) => {
157-
expect(err).to.not.exist()
158-
cb()
159-
})
160-
},
161-
(cb) => {
162-
// Waiting to make sure nodes are connected
163-
setTimeout(cb, 1000)
164-
},
156+
(cb) => nodeA.swarm.connect(nodeBAddress, cb),
157+
(cb) => setTimeout(cb, 1000), // time for identify
165158
(cb) => {
166159
nodeA.swarm.peers((err, peers) => {
167160
expect(err).to.not.exist()
@@ -183,14 +176,15 @@ module.exports = (common) => {
183176
let nodeA
184177
let nodeB
185178
let nodeBAddress
179+
180+
// TODO: Change to port 0, needs: https://github.com/ipfs/interface-ipfs-core/issues/152
186181
const configA = getConfig([
187-
// TODO: Change to port 0, needs: https://github.com/ipfs/interface-ipfs-core/issues/152
188-
'/ip4/127.0.0.1/tcp/6543',
189-
'/ip4/127.0.0.1/tcp/6544'
182+
'/ip4/127.0.0.1/tcp/16543',
183+
'/ip4/127.0.0.1/tcp/16544'
190184
])
191185
const configB = getConfig([
192-
'/ip4/127.0.0.1/tcp/6545',
193-
'/ip4/127.0.0.1/tcp/6546'
186+
'/ip4/127.0.0.1/tcp/26545',
187+
'/ip4/127.0.0.1/tcp/26546'
194188
])
195189
series([
196190
(cb) => {
@@ -214,16 +208,8 @@ module.exports = (common) => {
214208
cb()
215209
})
216210
},
217-
(cb) => {
218-
nodeA.swarm.connect(nodeBAddress, (err) => {
219-
expect(err).to.not.exist()
220-
cb()
221-
})
222-
},
223-
(cb) => {
224-
// Waiting to make sure nodes are connected
225-
setTimeout(cb, 1000)
226-
},
211+
(cb) => nodeA.swarm.connect(nodeBAddress, cb),
212+
(cb) => setTimeout(cb, 1000), // time for identify
227213
(cb) => {
228214
nodeA.swarm.peers((err, peers) => {
229215
expect(err).to.not.exist()

0 commit comments

Comments
 (0)