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

Commit

Permalink
fix: ping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 31, 2018
1 parent 2e822b6 commit cd00d5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 45 deletions.
21 changes: 3 additions & 18 deletions js/src/ping/ping-pull-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = (createCommon, options) => {
const common = createCommon()

describe('.pingPullStream', function () {
this.timeout(60 * 1000)
this.timeout(30 * 1000)

let ipfsA
let ipfsB
Expand Down Expand Up @@ -61,26 +61,12 @@ module.exports = (createCommon, options) => {
})

it('should fail when pinging an unknown peer over pull stream', (done) => {
let messageNum = 0
const unknownPeerId = 'QmUmaEnH1uMmvckMZbh3yShaasvELPW4ZLPWnB4entMTEn'
const count = 2
pull(
ipfsA.pingPullStream(unknownPeerId, { count }),
pull.drain((res) => {
expectIsPingResponse(res)
messageNum++

// First message should be "looking up" response
if (messageNum === 1) {
expect(res.text).to.include('Looking up')
}

// Second message should be a failure response
if (messageNum === 2) {
expect(res.success).to.be.false()
}
}, (err) => {
expect(err).to.not.exist()
pull.collect((err, results) => {
expect(err).to.exist()
done()
})
)
Expand All @@ -94,7 +80,6 @@ module.exports = (createCommon, options) => {
pull.collect((err, results) => {
expect(err).to.exist()
expect(err.message).to.include('failed to parse peer address')
expect(results).to.not.exist()
done()
})
)
Expand Down
28 changes: 5 additions & 23 deletions js/src/ping/ping-readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (createCommon, options) => {
const common = createCommon()

describe('.pingReadableStream', function () {
this.timeout(60 * 1000)
this.timeout(30 * 1000)

let ipfsA
let ipfsB
Expand Down Expand Up @@ -69,44 +69,26 @@ module.exports = (createCommon, options) => {
})

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

pump(
ipfsA.pingReadableStream(unknownPeerId, { count }),
ipfsA.pingReadableStream(unknownPeerId, {}),
new Writable({
objectMode: true,
write (res, enc, cb) {
expectIsPingResponse(res)
messageNum++

// First message should be "looking up" response
if (messageNum === 1) {
expect(res.text).to.include('Looking up')
}

// Second message should be a failure response
if (messageNum === 2) {
expect(res.success).to.be.false()
}

cb()
}
write: (res, enc, cb) => cb()
}),
(err) => {
expect(err).to.not.exist()
expect(err).to.exist()
done()
}
)
})

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

pump(
ipfsA.pingReadableStream(invalidPeerId, { count }),
ipfsA.pingReadableStream(invalidPeerId, {}),
new Writable({
objectMode: true,
write: (chunk, enc, cb) => cb()
Expand Down
6 changes: 2 additions & 4 deletions js/src/ping/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = (createCommon, options) => {
const common = createCommon()

describe('.ping', function () {
this.timeout(60 * 1000)
this.timeout(30 * 1000)

let ipfsA
let ipfsB
Expand Down Expand Up @@ -56,9 +56,7 @@ module.exports = (createCommon, options) => {
const count = 2

ipfsA.ping(notAvailablePeerId, { count }, (err, responses) => {
expect(err).to.not.exist()
expect(responses[0].text).to.include('Looking up')
expect(responses[1].success).to.be.false()
expect(err).to.exist()
done()
})
})
Expand Down

0 comments on commit cd00d5d

Please sign in to comment.