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

Commit cd00d5d

Browse files
committed
fix: ping tests
1 parent 2e822b6 commit cd00d5d

File tree

3 files changed

+10
-45
lines changed

3 files changed

+10
-45
lines changed

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

+3-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = (createCommon, options) => {
1414
const common = createCommon()
1515

1616
describe('.pingPullStream', function () {
17-
this.timeout(60 * 1000)
17+
this.timeout(30 * 1000)
1818

1919
let ipfsA
2020
let ipfsB
@@ -61,26 +61,12 @@ module.exports = (createCommon, options) => {
6161
})
6262

6363
it('should fail when pinging an unknown peer over pull stream', (done) => {
64-
let messageNum = 0
6564
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
6665
const count = 2
6766
pull(
6867
ipfsA.pingPullStream(unknownPeerId, { count }),
69-
pull.drain((res) => {
70-
expectIsPingResponse(res)
71-
messageNum++
72-
73-
// First message should be "looking up" response
74-
if (messageNum === 1) {
75-
expect(res.text).to.include('Looking up')
76-
}
77-
78-
// Second message should be a failure response
79-
if (messageNum === 2) {
80-
expect(res.success).to.be.false()
81-
}
82-
}, (err) => {
83-
expect(err).to.not.exist()
68+
pull.collect((err, results) => {
69+
expect(err).to.exist()
8470
done()
8571
})
8672
)
@@ -94,7 +80,6 @@ module.exports = (createCommon, options) => {
9480
pull.collect((err, results) => {
9581
expect(err).to.exist()
9682
expect(err.message).to.include('failed to parse peer address')
97-
expect(results).to.not.exist()
9883
done()
9984
})
10085
)

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

+5-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = (createCommon, options) => {
1515
const common = createCommon()
1616

1717
describe('.pingReadableStream', function () {
18-
this.timeout(60 * 1000)
18+
this.timeout(30 * 1000)
1919

2020
let ipfsA
2121
let ipfsB
@@ -69,44 +69,26 @@ module.exports = (createCommon, options) => {
6969
})
7070

7171
it('should fail when pinging peer that is not available over readable stream', (done) => {
72-
let messageNum = 0
7372
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
74-
const count = 2
7573

7674
pump(
77-
ipfsA.pingReadableStream(unknownPeerId, { count }),
75+
ipfsA.pingReadableStream(unknownPeerId, {}),
7876
new Writable({
7977
objectMode: true,
80-
write (res, enc, cb) {
81-
expectIsPingResponse(res)
82-
messageNum++
83-
84-
// First message should be "looking up" response
85-
if (messageNum === 1) {
86-
expect(res.text).to.include('Looking up')
87-
}
88-
89-
// Second message should be a failure response
90-
if (messageNum === 2) {
91-
expect(res.success).to.be.false()
92-
}
93-
94-
cb()
95-
}
78+
write: (res, enc, cb) => cb()
9679
}),
9780
(err) => {
98-
expect(err).to.not.exist()
81+
expect(err).to.exist()
9982
done()
10083
}
10184
)
10285
})
10386

10487
it('should fail when pinging an invalid peer id over readable stream', (done) => {
10588
const invalidPeerId = 'not a peer ID'
106-
const count = 2
10789

10890
pump(
109-
ipfsA.pingReadableStream(invalidPeerId, { count }),
91+
ipfsA.pingReadableStream(invalidPeerId, {}),
11092
new Writable({
11193
objectMode: true,
11294
write: (chunk, enc, cb) => cb()

js/src/ping/ping.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = (createCommon, options) => {
1313
const common = createCommon()
1414

1515
describe('.ping', function () {
16-
this.timeout(60 * 1000)
16+
this.timeout(30 * 1000)
1717

1818
let ipfsA
1919
let ipfsB
@@ -56,9 +56,7 @@ module.exports = (createCommon, options) => {
5656
const count = 2
5757

5858
ipfsA.ping(notAvailablePeerId, { count }, (err, responses) => {
59-
expect(err).to.not.exist()
60-
expect(responses[0].text).to.include('Looking up')
61-
expect(responses[1].success).to.be.false()
59+
expect(err).to.exist()
6260
done()
6361
})
6462
})

0 commit comments

Comments
 (0)