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

Cancel the active request instead of the most recent request #2696

Merged
merged 5 commits into from Oct 8, 2020

Conversation

selamanse
Copy link
Contributor

Closes #2690

I replaced the inner network.js variable cancelRequestFunction with a Map that remembers the requestId of the given cancelFunction.

Also the ui now uses cancelRequestById with the actual requestId to cancel the specific request.

I tested package insomnia-app locally via ui with the express based test-server that was proposed by the issue description (very helpful and precise by the way).

I also ran all tests with npm test locally from repository root...all seem fine.

I am unsure about ui or module tests. Is there something I should add?

Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

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

I'm really impressed, brilliant work 👏

I am unsure about ui or module tests. Is there something I should add?

Currently there are no UI tests (this is WIP as I'd like to add them too).

Some tests could potentially be added for the cancelRequestById function in network.test.js though. Looks like there are only tests for _actuallySend, which sets up the cancellation logic, so we might be able to add a few test cases to also cancel.

Give that a go, and if it's non-trivial to add tests for cancellation then I'll merge this in as-is. Looks pretty good to me!

packages/insomnia-app/app/network/network.js Show resolved Hide resolved
Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

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

Small change about clearing the cancel function once a request completes or is cancelled, to avoid a memory leak 😄

Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

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

Your update to the unit test was exactly what I had in mind, nice work!

A couple of comments, almost there 🤗

packages/insomnia-app/app/network/network.js Outdated Show resolved Hide resolved
packages/insomnia-app/app/network/network.js Outdated Show resolved Hide resolved
Copy link
Contributor

@develohpanda develohpanda left a comment

Choose a reason for hiding this comment

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

Nicely done 💯

@develohpanda
Copy link
Contributor

I did some manual testing:

  • cancelled requests
  • successful requests
  • failed requests (invalid url)

Cancel functions didn't persist longer than necessary. So excited to merge this!

@develohpanda develohpanda changed the title Add logic to cancelRequest to remember requestId Cancel the active request instead of the most recent request Oct 8, 2020
@develohpanda develohpanda merged commit 03d83a8 into Kong:develop Oct 8, 2020
@selamanse
Copy link
Contributor Author

selamanse commented Oct 8, 2020

@develohpanda thanks for reviewing and advising. I appreciate this.

@develohpanda
Copy link
Contributor

Credit where credit is due, @DMarby noticed the memory leak, and you did a great job with fixing it up.

I was certainly impressed with your refined unit test as well! 🥇

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.

Starting two requests and cancelling the first one does not behave as expected
2 participants