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

When tests are stopped by timeout, pending promises continue execution #9685

Closed
4ekki opened this issue Mar 19, 2020 · 10 comments
Closed

When tests are stopped by timeout, pending promises continue execution #9685

4ekki opened this issue Mar 19, 2020 · 10 comments

Comments

@4ekki
Copy link

4ekki commented Mar 19, 2020

🐛 Bug Report

When tests are stopped by timeout, pending promises continue execution

To Reproduce

Run the following test:

jest.setTimeout(3000);

beforeAll(async () => {
  await longFunction(); 
});

test("Test name", async () => {
  expect(1).toBeTruthy();
});

afterAll(async () => {
  await sleep(5000);
  console.log(3)
});

async function longFunction() {
  console.log(1);
  await sleep(5000)
  console.log(2);  
}

function sleep(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

Actual behavior

'2' is written in console
image

Expected behavior

longFunction execution is stopped after 3 sec, therefore '2' is not written in console.

envinfo

λ npx envinfo --preset jest
npx: installed 1 in 1.668s

  System:
    OS: Windows 10 10.0.18362
    CPU: (8) x64 Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz
  Binaries:
    Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.17.3 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: 25.1.0 => 25.1.0
@4ekki
Copy link
Author

4ekki commented Mar 19, 2020

This often leads to Jest did not exit one second after the test run has completed. behavior and various errors. F.e., I close my logger in afterAll function and if longFunction tries to log something in this moment, network error will occur.

@thernstig
Copy link
Contributor

@4ekki You missed the jest.setTimeout(3000); in the pasted example, which kind of makes it harder to understand your example since the default is 5000. Would be good if you update. I noticed that by looking at the image. Also, are you using jest-circus?

@4ekki
Copy link
Author

4ekki commented Apr 6, 2020

@thernstig, thank you for pointing this out. For some reason, github hides everything in the same line, where triple-quote code macro starts. Added new line and it was ok=)

Yes, I use jest-circus.

@thernstig
Copy link
Contributor

thernstig commented Apr 6, 2020

@4ekki No worries. Also, if you add this to the start triple single-quote it looks even nicer. Like this.

```javascript

That is why it was hidden for you, since it is actually a feature.

I also found these, do you recon this is a duplicate?
#8442
#8688
#8654 (someone trying to fix it?)

Although I like your simple repro better even with an image.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 17, 2023
@4ekki
Copy link
Author

4ekki commented Feb 20, 2023

Not stale

@github-actions github-actions bot removed the Stale label Feb 20, 2023
@16oh4
Copy link

16oh4 commented Jul 31, 2023

I'm running into this issue also

Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Jul 30, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 29, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants