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

Commit 8a4e482

Browse files
committed
chore: do not rely on discovery for ping tests
As per original PR #311 License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent bd5aac6 commit 8a4e482

File tree

6 files changed

+30
-88
lines changed

6 files changed

+30
-88
lines changed

js/src/bitswap/unwant.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
'use strict'
33

44
const waterfall = require('async/waterfall')
5-
const { waitUntilConnected } = require('../utils/connections')
6-
const { spawnNodes } = require('../utils/spawn')
5+
const { spawnNodesWithId } = require('../utils/spawn')
76
const { getDescribe, getIt, expect } = require('../utils/mocha')
87
const { waitForWantlistKey } = require('./utils')
98

@@ -25,7 +24,7 @@ module.exports = (createCommon, options) => {
2524
common.setup((err, factory) => {
2625
expect(err).to.not.exist()
2726

28-
spawnNodes(2, factory, (err, nodes) => {
27+
spawnNodesWithId(2, factory, (err, nodes) => {
2928
expect(err).to.not.exist()
3029

3130
ipfsA = nodes[0]
@@ -34,7 +33,7 @@ module.exports = (createCommon, options) => {
3433
// Add key to the wantlist for ipfsB
3534
ipfsB.block.get(key, () => {})
3635

37-
waitUntilConnected(ipfsA, ipfsB, done)
36+
ipfsA.swarm.connect(ipfsB.peerId.addresses[0], done)
3837
})
3938
})
4039
})

js/src/bitswap/wantlist.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
'use strict'
33

44
const waterfall = require('async/waterfall')
5-
const { waitUntilConnected } = require('../utils/connections')
6-
const { spawnNodes } = require('../utils/spawn')
5+
const { spawnNodesWithId } = require('../utils/spawn')
76
const { getDescribe, getIt, expect } = require('../utils/mocha')
87
const { waitForWantlistKey } = require('./utils')
98

@@ -25,7 +24,7 @@ module.exports = (createCommon, options) => {
2524
common.setup((err, factory) => {
2625
expect(err).to.not.exist()
2726

28-
spawnNodes(2, factory, (err, nodes) => {
27+
spawnNodesWithId(2, factory, (err, nodes) => {
2928
expect(err).to.not.exist()
3029

3130
ipfsA = nodes[0]
@@ -34,7 +33,7 @@ module.exports = (createCommon, options) => {
3433
// Add key to the wantlist for ipfsB
3534
ipfsB.block.get(key, () => {})
3635

37-
waitUntilConnected(ipfsA, ipfsB, done)
36+
ipfsA.swarm.connect(ipfsB.peerId.addresses[0], done)
3837
})
3938
})
4039
})

js/src/ping/ping-pull-stream.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const pull = require('pull-stream')
55
const series = require('async/series')
66
const { spawnNodesWithId } = require('../utils/spawn')
7-
const { waitUntilConnected } = require('../utils/connections')
87
const { getDescribe, getIt, expect } = require('../utils/mocha')
98
const { expectIsPingResponse, isPong } = require('./utils')
109

@@ -16,8 +15,8 @@ module.exports = (createCommon, options) => {
1615
describe('.pingPullStream', function () {
1716
this.timeout(15 * 1000)
1817

19-
let ipfsdA
20-
let ipfsdB
18+
let ipfsA
19+
let ipfsB
2120

2221
before(function (done) {
2322
this.timeout(60 * 1000)
@@ -29,12 +28,12 @@ module.exports = (createCommon, options) => {
2928
(cb) => {
3029
spawnNodesWithId(2, factory, (err, nodes) => {
3130
if (err) return cb(err)
32-
ipfsdA = nodes[0]
33-
ipfsdB = nodes[1]
31+
ipfsA = nodes[0]
32+
ipfsB = nodes[1]
3433
cb()
3534
})
3635
},
37-
(cb) => waitUntilConnected(ipfsdA, ipfsdB, cb)
36+
(cb) => ipfsA.swarm.connect(ipfsB.peerId.addresses[0], cb)
3837
], done)
3938
})
4039
})
@@ -45,7 +44,7 @@ module.exports = (createCommon, options) => {
4544
let packetNum = 0
4645
const count = 3
4746
pull(
48-
ipfsdA.pingPullStream(ipfsdB.peerId.id, { count }),
47+
ipfsA.pingPullStream(ipfsB.peerId.id, { count }),
4948
pull.drain((res) => {
5049
expect(res.success).to.be.true()
5150
// It's a pong
@@ -65,7 +64,7 @@ module.exports = (createCommon, options) => {
6564
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
6665
const count = 2
6766
pull(
68-
ipfsdA.pingPullStream(unknownPeerId, { count }),
67+
ipfsA.pingPullStream(unknownPeerId, { count }),
6968
pull.drain((res) => {
7069
expectIsPingResponse(res)
7170
messageNum++
@@ -90,7 +89,7 @@ module.exports = (createCommon, options) => {
9089
const invalidPeerId = 'not a peer ID'
9190
const count = 2
9291
pull(
93-
ipfsdA.pingPullStream(invalidPeerId, { count }),
92+
ipfsA.pingPullStream(invalidPeerId, { count }),
9493
pull.collect((err) => {
9594
expect(err).to.exist()
9695
expect(err.message).to.include('failed to parse peer address')

js/src/ping/ping-readable-stream.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const pump = require('pump')
55
const { Writable } = require('stream')
66
const series = require('async/series')
77
const { spawnNodesWithId } = require('../utils/spawn')
8-
const { waitUntilConnected } = require('../utils/connections')
98
const { getDescribe, getIt, expect } = require('../utils/mocha')
109
const { expectIsPingResponse, isPong } = require('./utils')
1110

@@ -17,8 +16,8 @@ module.exports = (createCommon, options) => {
1716
describe('.pingReadableStream', function () {
1817
this.timeout(15 * 1000)
1918

20-
let ipfsdA
21-
let ipfsdB
19+
let ipfsA
20+
let ipfsB
2221

2322
before(function (done) {
2423
this.timeout(60 * 1000)
@@ -30,12 +29,12 @@ module.exports = (createCommon, options) => {
3029
(cb) => {
3130
spawnNodesWithId(2, factory, (err, nodes) => {
3231
if (err) return cb(err)
33-
ipfsdA = nodes[0]
34-
ipfsdB = nodes[1]
32+
ipfsA = nodes[0]
33+
ipfsB = nodes[1]
3534
cb()
3635
})
3736
},
38-
(cb) => waitUntilConnected(ipfsdA, ipfsdB, cb)
37+
(cb) => ipfsA.swarm.connect(ipfsB.peerId.addresses[0], cb)
3938
], done)
4039
})
4140
})
@@ -47,7 +46,7 @@ module.exports = (createCommon, options) => {
4746
const count = 3
4847

4948
pump(
50-
ipfsdA.pingReadableStream(ipfsdB.peerId.id, { count }),
49+
ipfsA.pingReadableStream(ipfsB.peerId.id, { count }),
5150
new Writable({
5251
objectMode: true,
5352
write (res, enc, cb) {
@@ -74,7 +73,7 @@ module.exports = (createCommon, options) => {
7473
const count = 2
7574

7675
pump(
77-
ipfsdA.pingReadableStream(unknownPeerId, { count }),
76+
ipfsA.pingReadableStream(unknownPeerId, { count }),
7877
new Writable({
7978
objectMode: true,
8079
write (res, enc, cb) {
@@ -106,7 +105,7 @@ module.exports = (createCommon, options) => {
106105
const count = 2
107106

108107
pump(
109-
ipfsdA.pingReadableStream(invalidPeerId, { count }),
108+
ipfsA.pingReadableStream(invalidPeerId, { count }),
110109
new Writable({
111110
objectMode: true,
112111
write: (chunk, enc, cb) => cb()

js/src/ping/ping.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
const series = require('async/series')
55
const { spawnNodesWithId } = require('../utils/spawn')
6-
const { waitUntilConnected } = require('../utils/connections')
76
const { getDescribe, getIt, expect } = require('../utils/mocha')
87
const { expectIsPingResponse, isPong } = require('./utils')
98

@@ -15,8 +14,8 @@ module.exports = (createCommon, options) => {
1514
describe('.ping', function () {
1615
this.timeout(15 * 1000)
1716

18-
let ipfsdA
19-
let ipfsdB
17+
let ipfsA
18+
let ipfsB
2019

2120
before(function (done) {
2221
this.timeout(60 * 1000)
@@ -28,12 +27,12 @@ module.exports = (createCommon, options) => {
2827
(cb) => {
2928
spawnNodesWithId(2, factory, (err, nodes) => {
3029
if (err) return cb(err)
31-
ipfsdA = nodes[0]
32-
ipfsdB = nodes[1]
30+
ipfsA = nodes[0]
31+
ipfsB = nodes[1]
3332
cb()
3433
})
3534
},
36-
(cb) => waitUntilConnected(ipfsdA, ipfsdB, cb)
35+
(cb) => ipfsA.swarm.connect(ipfsB.peerId.addresses[0], cb)
3736
], done)
3837
})
3938
})
@@ -42,7 +41,7 @@ module.exports = (createCommon, options) => {
4241

4342
it('should send the specified number of packets', (done) => {
4443
const count = 3
45-
ipfsdA.ping(ipfsdB.peerId.id, { count }, (err, responses) => {
44+
ipfsA.ping(ipfsB.peerId.id, { count }, (err, responses) => {
4645
expect(err).to.not.exist()
4746
responses.forEach(expectIsPingResponse)
4847
const pongs = responses.filter(isPong)
@@ -55,7 +54,7 @@ module.exports = (createCommon, options) => {
5554
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
5655
const count = 2
5756

58-
ipfsdA.ping(unknownPeerId, { count }, (err, responses) => {
57+
ipfsA.ping(unknownPeerId, { count }, (err, responses) => {
5958
expect(err).to.exist()
6059
expect(responses[0].text).to.include('Looking up')
6160
expect(responses[1].success).to.be.false()
@@ -66,7 +65,7 @@ module.exports = (createCommon, options) => {
6665
it('should fail when pinging an invalid peer', (done) => {
6766
const invalidPeerId = 'not a peer ID'
6867
const count = 2
69-
ipfsdA.ping(invalidPeerId, { count }, (err, responses) => {
68+
ipfsA.ping(invalidPeerId, { count }, (err, responses) => {
7069
expect(err).to.exist()
7170
expect(err.message).to.include('failed to parse peer address')
7271
done()

js/src/utils/connections.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)