-
Notifications
You must be signed in to change notification settings - Fork 479
add callback to pubsub.unsubscribe and test (#300) #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Not sure how to fix the remaining failing tests, sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry about the commitlint ci failure, I can resolve that during the merge. We use the commits to generate changelogs so they are prefixed with certain values to denote what should be updated in the changelog, such as feat:
, fix:
, test:
. Added a few notes on changes.
src/pubsub.js
Outdated
@@ -43,6 +43,8 @@ module.exports = (node) => { | |||
if (floodSub.listenerCount(topic) === 0) { | |||
floodSub.unsubscribe(topic) | |||
} | |||
|
|||
setImmediate(() => callback()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the callback is being added, even though it should have already exists, we should check that it is actually a function before invoking it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, I added a check
test/pubsub.node.js
Outdated
expect(err).to.not.exist() | ||
console.log('tunsubscribed!') | ||
done() | ||
}), 600) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should get rid of the timeouts in this test. Subscribing -> publishing -> unsubscribing should be able to be executed in serial successfully without a timeout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
test/pubsub.node.js
Outdated
nodes[0].pubsub.unsubscribe('pubsub', handler, (err) => { | ||
expect(err).to.not.exist() | ||
console.log('\tunsubscribed!') | ||
done() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible done could be called before we run the expect in the publish handler. It would be good to include chai-checkmark
in this file and mark each of the expects. That way we can do expect(4).checks(done)
so we can ensure everything is verified before finishing the test.
Remove the console.log as well and I think this is good to go. Thank you for the PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I've added chai-checkmark and the check to make sure all the expects happen, as well as moved done and got rid of the console.log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done()
is still being called here, so the test is finishing before expect check happens. Should just need to delete done on line 72.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I remove done()
at line 72, I get Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
If we place done()
at line 77, at the end of the waterfall, it works. I'm not sure if this correctly allows for the expect check to happen though.
Hey, any updates on this? |
Sorry for the delay, I've been away on holiday but am back now. The test done logic is still not happening correctly. Done is being called and is passed as a callback to waterfall, this isn't correct. The timeout you were hitting is probably because things aren't firing in the right order, or are being triggered early. I can take a deeper look at what the issue is later today. |
@jacobheun No worries! Sounds good, thanks. Let me know what issues you find. |
There were some errors in the test, primarily some of the function arguments and I think it was a bit hard to follow so I made some changes along with the fixes that hopefully make things a bit easier to read. it('start two nodes and send one message, then unsubscribe', (done) => {
// Check the final series error, and the publish handler
expect(2).checks(done)
let nodes
const data = Buffer.from('test')
const handler = (msg) => {
// verify the data is correct and mark the expect
expect(msg.data).to.eql(data).mark()
}
series([
// Start the nodes
(cb) => startTwo((err, _nodes) => {
nodes = _nodes
cb(err)
}),
// subscribe on the first
(cb) => nodes[0].pubsub.subscribe('pubsub', handler, cb),
// Wait a moment before publishing
(cb) => setTimeout(cb, 500),
// publish on the second
(cb) => nodes[1].pubsub.publish('pubsub', data, cb),
// unsubscribe on the first
(cb) => nodes[0].pubsub.unsubscribe('pubsub', handler, cb),
// Stop both nodes
(cb) => stopTwo(nodes, cb)
], (err) => {
// Verify there was no error, and mark the expect
expect(err).to.not.exist().mark()
})
}) If that looks good and makes sense to you can you push the update? |
@jacobheun That's a lot easier to follow, I think it makes sense. I'll push the changes now |
I'm going to look into the windows ci failure. It's possible it's just flakey, but it needs to get fixed either way. |
okay cool, let me know if I need to make any changes. |
@jacobheun hey, any updates or changes needed? |
@noot not yet, I was away last week, hoping to take a look at it this week. |
// Wait a moment before publishing | ||
(cb) => setTimeout(cb, 500), | ||
// publish on the second | ||
(cb) => nodes[1].pubsub.publish('pubsub', data, cb), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@noot sorry for the delay, it looks like the tests were just failing because windows needs some time before unsubscribing. This should fix it:
(cb) => nodes[1].pubsub.publish('pubsub', data, cb), | |
(cb) => nodes[1].pubsub.publish('pubsub', data, cb), | |
// Wait a moment before unsubscribing | |
(cb) => setTimeout(cb, 500), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the changes!
Co-authored-by: Alex Potsides <[email protected]>
## [1.0.13](libp2p/js-libp2p-crypto@v1.0.12...v1.0.13) (2023-03-10) ### Trivial Changes * Update .github/workflows/semantic-pull-request.yml [skip ci] ([b66007c](libp2p/js-libp2p-crypto@b66007c)) * Update .github/workflows/semantic-pull-request.yml [skip ci] ([110063c](libp2p/js-libp2p-crypto@110063c)) * Update .github/workflows/semantic-pull-request.yml [skip ci] ([c789b0c](libp2p/js-libp2p-crypto@c789b0c)) ### Dependencies * **dev:** upgrade aegir to `38.1.2` ([libp2p#302](libp2p/js-libp2p-crypto#302)) ([9d60e39](libp2p/js-libp2p-crypto@9d60e39))
As per the issue I opened: #300
Upon
pubsub.unsubscribe
, the node was successfully unsubscribing, however the callback was never being called, so there was no explicit way to confirm success.I have changed
unsubscribe
as to call the callback, so it now complies with the interface-ipfs-core spec. I have also added a test.Let me know if any changes are needed, thanks!