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

Skip one-time request handlers inside the response reducer so it handles a scenario with parallel requests #583

Merged

Conversation

fnmunhoz
Copy link
Contributor

@fnmunhoz fnmunhoz commented Feb 6, 2021

I came across an issue where a one-time request handler is used more than once.

After some investigation, I created an automated test where it fails (actually, it failed only with setupServer and worked fine with setupWorker).

Apparently, the problem is related to multiple requests running in parallel (i.e., not awaited).

The test passes by moving the request handler "skip process" to inside the response reducer function.

I've also tried the MSW build with the change on the project where I initially identified the problem, and it also worked.

Please review and see if it's a viable solution or if you have other suggestions!

Ps: I've read the contribution guidelines and hope to have followed them, but I'm happy to update the PR if I missed something.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 6, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 443eb76:

Sandbox Source
MSW React Configuration

Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

Good catch! I added some comments

src/utils/getResponse.ts Outdated Show resolved Hide resolved
src/utils/getResponse.ts Outdated Show resolved Hide resolved
test/msw-api/setup-server/use.test.ts Outdated Show resolved Hide resolved
test/msw-api/setup-worker/use.test.ts Outdated Show resolved Hide resolved
src/utils/getResponse.ts Outdated Show resolved Hide resolved
Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Hey, @fnmunhoz. Thank you for an amazing contribution!

Everything looks good. There's one comment left regarding the bookId assertions in the responses. Also, please, rebase your branch against the latest master to get the response awaiting fix so there would be no need to include query parameters in 2 requests to the same URL. Those will be awaited properly now by default.

@fnmunhoz fnmunhoz changed the title Skip one-time request handlers inside the response reducer so it handles a scenario with multiple request promises Skip one-time request handlers inside the response reducer so it handles a scenario with parallel requests Feb 7, 2021
…les a scenario with multiple request promises
@fnmunhoz fnmunhoz force-pushed the feature/one-time-handler-parallel-requests branch from 98f9641 to 443eb76 Compare February 7, 2021 14:25
Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

The changes look great! Thank you for working on this, @fnmunhoz! It's an exemplary contribution and we're happy to receive it from you. You're awesome!

@kettanaito kettanaito merged commit 0173730 into mswjs:master Feb 7, 2021
@fnmunhoz
Copy link
Contributor Author

fnmunhoz commented Feb 7, 2021

Yay! Thanks for all your help in the review @kettanaito and @timdeschryver 🚀

I learned a lot about MSW, and I hope I can contribute more soon!

I appreciate the fantastic work you have been doing for this project. It makes my automated tests at work way better. 🤓

@kettanaito
Copy link
Member

We will be happy to collaborate more with you, @fnmunhoz! Feel free to tackle any issues you find interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants