Skip to content

fix: prevent handling in-flight requests after worker was stopped#2668

Draft
diego-aquino wants to merge 1 commit intomswjs:mainfrom
diego-aquino:fix/flaky-worker-stop
Draft

fix: prevent handling in-flight requests after worker was stopped#2668
diego-aquino wants to merge 1 commit intomswjs:mainfrom
diego-aquino:fix/flaky-worker-stop

Conversation

@diego-aquino
Copy link

I was investigating #2597 and comparing the reproduction repository with MSW's test suite. The reproduction tests frequently fail due to requests still being handled after the worker was stopped.

However, the existing MSW test checking this behavior does not appear to be flaky:

test('bypasses requests made after the worker was stopped', async ({

I've created two new test cases to better understand the problem:

  1. bypasses requests not immediately made after the worker was stopped, considering no default response

    This test stops the worker and makes a request in different page.evaluate calls. It checks if the request was bypassed by expecting a Cannot GET response text. From my local executions, it always passes.

  2. bypasses requests immediately made after the worker was stopped, considering no default response

    This test stops the worker and makes a request in the same page.evaluate call. Similarly to test 1, it expects a Cannot GET response text, but it shows the same flaky behavior as the reproduction tests, although less frequently.

Here's an example of a failure:

1) [chromium]  test/browser/msw-api/setup-worker/stop/in-flight-request.test.ts:67:3 
   bypasses requests immediately made after the worker was stopped, considering no default response (40) 

  Error: expect(received).toContain(expected) // indexOf

  Expected substring: "Cannot GET /resource"
  Received string:    "hello world"

     98 |     })
     99 |
  > 100 |     expect(data).toContain('Cannot GET /resource')
        |                  ^
    101 |   })
    102 | }
    103 |

Note

I've added a for loop to repeat the new tests and make them more likely to fail. Still, not all test executions cause failures. Run them a couple of times if they continue to pass.

pnpm test:browser in-flight-request.test.ts

Maybe the overhead of page.evaluate is masking the issue in the existing test?


This pull request does not yet contain any changes to the source code. I've only added tests trying to simulate the issue.

@kettanaito, as I'm new to the codebase, I'm not yet sure about how to fix this. I'm willing to contribute after hearing your feedback and possible courses of action. Thanks!

Closes #2597.

This adds two temporary test cases to help us investigate requests still being handled by workers
after they are stopped. Related to mswjs#2597.
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.

MSW sometimes still handles requests after worker was stopped

1 participant