openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] `Exceeded timeout of 5000 ms for a test` error in jest

Open kasir-barati opened this issue 1 year ago • 3 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Hi, I am facing a very weird behavior for the code that is generated based on my API, it is working for the most part except that when I make another HTTP call to an external API (e.g. http://localhost:9011) with fetch and then make my Ajax call with the generated code it stucks and when I comment that first http call it does not (this test suit).

Please note that the first http call is taking only a mere 193ms, it is not even a second to get the expected result. So I am completely lost. And that is why I thought of it as a bug and I hope I am not alone on that conclusion.

openapi-generator version

7.5.0

OpenAPI declaration file content or url

openApi.json

Generation Details
  1. Clone the repo
  2. Install deps: npm ci
  3. npx nx test:e2e:docker backend-e2e
  4. Wait for the configuration and bootstraping app to complete (if for any reason you got an error before tests start to run please reexcute the command)
  5. Check you terminal and see the error
 FAIL   backend-e2e  apps/backend-e2e/src/auth/auth-business.e2e-spec.ts (7.827 s)
  ● Console

    console.log
      <STUCK>

      at src/auth/auth-business.e2e-spec.ts:204:15

  ● Auth -- business › POST /auth/refresh › should refresh tokens

    thrown: "Exceeded timeout of 5000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      196 |
      197 |   describe('POST /auth/refresh', () => {
    > 198 |     it('should refresh tokens', async () => {
          |     ^
      199 |       const tempUser = getTempUser();
      200 |       const authenticationResult = await login({
      201 |         username: tempUser.email,

      at src/auth/auth-business.e2e-spec.ts:198:5
      at src/auth/auth-business.e2e-spec.ts:197:3
      at Object.<anonymous> (src/auth/auth-business.e2e-spec.ts:19:1)

 PASS   backend-e2e  apps/backend-e2e/src/app/app.e2e-spec.ts

Test Suites: 1 failed, 2 passed, 3 total
Tests:       1 failed, 39 passed, 40 total
Snapshots:   0 total
Time:        11.904 s
Ran all test suites.
Warning: command "NODE_ENV=test jest --config apps/backend-e2e/jest-e2e.config.ts" exited with non-zero status code
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target test:e2e for project backend-e2e (14s)

   ✖  1/1 failed
   ✔  0/1 succeeded [0 read from cache]
Steps to reproduce

Explained in the previous section.

Related issues/PRs

Could not find any.

Suggest a fix

Axios/jest should send the request like normal without caring that I am making a separate Ajax call with fetch just how it does work with other test suits. Here is another test suit that passes without any error while making same Ajax call before sending a request with the generated code.

kasir-barati avatar Apr 21 '24 16:04 kasir-barati

Oddly enough now when I use .only on the aforementioned test suit passes :exploding_head:.

kasir-barati avatar Apr 21 '24 17:04 kasir-barati

This could mean that the tests are not properly isolated from each other. Can you check to see if there are they shared objects / Puppeteer instances used by multiple tests?

0x326 avatar Apr 25 '24 21:04 0x326

@0x326 I do not think so, it is a simple login function that sends a http request to my backend. And as you can see in this test unit I am not suing any share thingy except for that login helper function and getTempUser which only returns an object, containing user's email and pass.

So I really doubt it, I already have mentioned it that other test suits work just fine except this one and ASAP I comment that login step it won't stuck but then it is not really what I need. I have to be authenticated and authorized to for that test :slightly_smiling_face:.

kasir-barati avatar Apr 26 '24 07:04 kasir-barati