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

Commit

Permalink
test: all pubsub tests passing (#1094)
Browse files Browse the repository at this point in the history
* all pubsub tests passing
* config.replace is not supported anymore
  • Loading branch information
daviddias authored Nov 20, 2017
1 parent b98739f commit bd264f2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"form-data": "^2.3.1",
"gulp": "^3.9.1",
"hat": "0.0.3",
"interface-ipfs-core": "~0.36.6",
"interface-ipfs-core": "~0.36.7",
"ipfsd-ctl": "~0.24.1",
"left-pad": "^1.2.0",
"lodash": "^4.17.4",
Expand Down Expand Up @@ -121,7 +121,7 @@
"joi": "^13.0.2",
"libp2p": "~0.13.1",
"libp2p-circuit": "~0.1.4",
"libp2p-floodsub": "~0.11.1",
"libp2p-floodsub": "~0.12.1",
"libp2p-kad-dht": "~0.6.0",
"libp2p-mdns": "~0.9.1",
"libp2p-multiplex": "~0.5.0",
Expand Down
38 changes: 16 additions & 22 deletions src/core/components/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,34 @@ module.exports = function pubsub (self) {
options = {}
}

function subscribe (cb) {
if (self._pubsub.listenerCount(topic) === 0) {
self._pubsub.subscribe(topic)
}

self._pubsub.on(topic, handler)
setImmediate(() => callback())

This comment has been minimized.

Copy link
@negamaxi

negamaxi Dec 8, 2017

Contributor

Doesn't it should be cb() instead of callback() here? This line seems to cause an error when trying to use subscribe promise-way:

await ipfs.pubsub.subscribe(topic, handleMessage)
// Uncaught TypeError: callback is not a function
}

if (!callback) {
return new Promise((resolve, reject) => {
subscribe(topic, options, handler, (err) => {
subscribe((err) => {
if (err) {
return reject(err)
}
resolve()
})
})
} else {
subscribe(callback)
}

subscribe(topic, options, handler, callback)
},

unsubscribe: (topic, handler) => {
const ps = self._pubsub

ps.removeListener(topic, handler)
self._pubsub.removeListener(topic, handler)

if (ps.listenerCount(topic) === 0) {
ps.unsubscribe(topic)
if (self._pubsub.listenerCount(topic) === 0) {
self._pubsub.unsubscribe(topic)
}
},

Expand All @@ -60,9 +67,7 @@ module.exports = function pubsub (self) {
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
}

const subscriptions = Array.from(
self._pubsub.subscriptions
)
const subscriptions = Array.from(self._pubsub.subscriptions)

setImmediate(() => callback(null, subscriptions))
}),
Expand All @@ -83,15 +88,4 @@ module.exports = function pubsub (self) {
return self._pubsub.setMaxListeners(n)
}
}

function subscribe (topic, options, handler, callback) {
const ps = self._pubsub

if (ps.listenerCount(topic) === 0) {
ps.subscribe(topic)
}

ps.on(topic, handler)
setImmediate(() => callback())
}
}
2 changes: 1 addition & 1 deletion test/cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('config', () => runOnAndOff((thing) => {
})
})

describe('replace', () => {
describe.skip('replace', () => {
it('replace config with file', () => {
const filePath = 'test/fixtures/test-data/otherconfig'
const expectedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8'))
Expand Down
2 changes: 1 addition & 1 deletion test/http-api/over-ipfs-api/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = (ctl) => {

// This one is one stale mode till go-ipfs decides
// what to do with the .replace command
describe('.replace', () => {
describe.skip('.replace', () => {
it('returns error if the config is invalid', (done) => {
const filePath = 'test/fixtures/test-data/badconfig'

Expand Down
2 changes: 1 addition & 1 deletion test/http-api/spec/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module.exports = (http) => {
})
})

describe('/config/replace', () => {
describe.skip('/config/replace', () => {
it('returns 400 if no config is provided', (done) => {
const form = new FormData()
const headers = form.getHeaders()
Expand Down

0 comments on commit bd264f2

Please sign in to comment.