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

Access the number of workers in globalSetup #10552

Closed
osdiab opened this issue Sep 24, 2020 · 8 comments
Closed

Access the number of workers in globalSetup #10552

osdiab opened this issue Sep 24, 2020 · 8 comments

Comments

@osdiab
Copy link

osdiab commented Sep 24, 2020

🚀 Feature Proposal

Add an environment variable or otherwise expose to the globalSetup script how many jest workers are being spun up for a test run

Motivation

I want to setup n separate databases to run database tests in parallel while still maintaining isolation from a globalSetup script that happens before all test suites, and then access them based on the JEST_WORKER_ID flag, like described in this article. But unfortunately it doesn't seem like the JEST_WORKERS env var in that article actually exists; I can't find it in my environment nor in the jest source by searching for it here on Github source, issues, PRs.

Example

See the article linked above

Pitch

Jest internally decides the number of workers so it's not straightforward to do this outside of it if I understand correctly

@osdiab
Copy link
Author

osdiab commented Sep 24, 2020

i worked around this by assuming that maxWorkers is going to be the total number of workers - just realized that that piece of config is passed to the function that the globalSetup module exports. That works for me for now, though would be nice if the actually authoritative number were passed.

@rinogo
Copy link

rinogo commented Jan 6, 2022

One thing to keep in mind is that maxWorkers "defaults to the number of the cores available on your machine minus one for the main thread".

I was looking for a way to use more workers, but the default setting actually seems like it might be ideal.

@github-actions
Copy link

github-actions bot commented Jan 6, 2023

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 Jan 6, 2023
@SimenB
Copy link
Member

SimenB commented Jan 6, 2023

This is passed as config to the exported function, isn't it?

@github-actions github-actions bot removed the Stale label Jan 6, 2023
@alencarandre
Copy link

I am using jest version 29.3.1 and I found it

process.env.JEST_WORKER_ID

@d4vidi
Copy link
Contributor

d4vidi commented Jan 15, 2023

I am using jest version 29.3.1 and I found it

process.env.JEST_WORKER_ID

@alencarandre I think this stands for the unique ID each worker has, rather than the total count.

@SimenB
Copy link
Member

SimenB commented Jan 15, 2023

Correct, that's something different.


#6486 made sure to pass globalConfig to the setup files, so you can just inspect that.

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2023
@github-actions
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 Feb 15, 2023
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

5 participants