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

fix: make ipfs.ping() options optional #1627

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/core/components/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const pull = require('pull-stream/pull')

module.exports = function ping (self) {
return promisify((peerId, opts, cb) => {
if (typeof opts === 'function') {
cb = opts
opts = {}
}

pull(
self.pingPullStream(peerId, opts),
pull.collect(cb)
Expand Down
64 changes: 62 additions & 2 deletions test/core/ping.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const isNode = require('detect-node')
const expect = chai.expect
chai.use(dirtyChai)
const df = DaemonFactory.create({ exec: 'src/cli/bin.js' })
const dfProc = DaemonFactory.create({
exec: require('../../'),
type: 'proc'
})

const config = {
Bootstrap: [],
Expand All @@ -24,9 +28,10 @@ const config = {
}
}

function spawnNode ({ dht = false }, cb) {
function spawnNode ({ dht = false, type = 'js' }, cb) {
const args = dht ? ['--enable-dht-experiment'] : []
df.spawn({
const factory = type === 'js' ? df : dfProc
factory.spawn({
args,
config,
initOptions: { bits: 512 }
Expand All @@ -43,6 +48,61 @@ describe('ping', function () {

if (!isNode) return

describe('in-process daemon', function () {
let ipfsdA
let ipfsdB
let bMultiaddr
let ipfsdBId

// Spawn nodes
before(function (done) {
this.timeout(60 * 1000)

series([
spawnNode.bind(null, { dht: false, type: 'proc' }),
spawnNode.bind(null, { dht: false })
], (err, ipfsd) => {
expect(err).to.not.exist()
ipfsdA = ipfsd[0]
ipfsdB = ipfsd[1]
done()
})
})

// Get the peer info object
before(async function () {
this.timeout(60 * 1000)

const peerInfo = await ipfsdB.api.id()

ipfsdBId = peerInfo.id
bMultiaddr = peerInfo.addresses[0]
})

// Connect the nodes
before(async function () {
this.timeout(60 * 1000)
await ipfsdA.api.swarm.connect(bMultiaddr)
})

after(async () => {
if (!ipfsdA) return
await ipfsdA.stop()
})

after(async () => {
if (!ipfsdB) return
await ipfsdB.stop()
})

it('can ping via a promise without options', async () => {
const res = await ipfsdA.api.ping(ipfsdBId)

expect(res.length).to.be.ok()
expect(res[0].success).to.be.true()
})
})

describe('DHT disabled', function () {
// Without DHT nodes need to be previously connected
let ipfsdA
Expand Down