Skip to content
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

chore: more code cleanup surrounding client.end callbacks #1629

Merged
merged 5 commits into from
Jul 10, 2023

Conversation

BertKleewein
Copy link
Contributor

More test changes surrounding client.end callbaacks. One // BUGBUG: comment marks a bug that I found with these changes.

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done with this cleanup! I would like to discuss about the "bugbug"

Comment on lines +113 to +114
// BUGBUG: the client.end callback never gets called here
// client.end((err) => done(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use mqttjs in lot of my projects and this happend to me too, I always create a MqttClient wrapper library that handles all client stuff, this is how I handle the close usually: https://github.com/zwave-js/zwave-js-ui/blob/master/lib/MqttClient.ts#L154. I think this could happen when for some reason underlig socket is already closed/destroyed or when store cannot be closed for some reason

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No clue if this could help: #713

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged #713 into a local branch and it didn't resolve this issue. It is an interesting change though.

One of my goals with these test changes is to get the behavior of client.end well tested before we make any changes to it. Right now, it's just too hard to reason about how client.end might behave and I'm afraid to make any changes to it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! Tests are essentials if we want to make improvements to the code

test/client.js Outdated
@@ -168,10 +173,10 @@ describe('MqttClient', function () {
unsubscribeCallbackCalled = true
})
setTimeout(() => {
client.end(() => {
client.end((err) => {
assert.strictEqual(pubCallbackCalled && unsubscribeCallbackCalled, true, 'callbacks not invoked')
server3.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does server3.close expects a callback too?

@codecov
Copy link

codecov bot commented Jul 7, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (31dd357) 86.22% compared to head (71620f3) 86.22%.

❗ Current head 71620f3 differs from pull request most recent head d1d2383. Consider uploading reports for the commit d1d2383 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1629   +/-   ##
=======================================
  Coverage   86.22%   86.22%           
=======================================
  Files          13       13           
  Lines        1321     1321           
=======================================
  Hits         1139     1139           
  Misses        182      182           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@robertsLando robertsLando enabled auto-merge (squash) July 10, 2023 12:01
@robertsLando robertsLando merged commit 3348814 into mqttjs:main Jul 10, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants