Test durations are inaccurate in for certain concurrent tests
Do you want to request a feature or report a bug? bug
What is the current behavior?
test.concurrent does not produce correct test durations. See MVP in
https://repl.it/@kachkaev/concurrent-test-durations-in-jest
What is the expected behavior?
works concurrently - 0.1 seconds per test
✓ concurrent #0 (100ms) <-- ok
✓ concurrent #1 (100ms) <-- currently incorrect (≈0-2ms)
✓ concurrent #2 (100ms) <-- currently incorrect (≈0-2ms)
✓ concurrent #3 (100ms) <-- currently incorrect (≈0-2ms)
✓ concurrent #4 (100ms) <-- currently incorrect (≈0-2ms)
sequential tests - 0.2 seconds per test
✓ sequential #0 (200ms) <-- ok
✓ sequential #1 (200ms) <-- ok
✓ sequential #2 (200ms) <-- ok
✓ sequential #3 (200ms) <-- ok
✓ sequential #4 (200ms) <-- ok
concurrent tests - 2 seconds per test
✓ concurrent again #0 (2000ms) <-- currently incorrect (≈1000ms), see footnote
✓ concurrent again #1 (2000ms) <-- currently incorrect (≈0-2ms)
✓ concurrent again #2 (2000ms) <-- currently incorrect (≈0-2ms)
✓ concurrent again #3 (2000ms) <-- currently incorrect (≈0-2ms)
✓ concurrent again #4 (2000ms) <-- currently incorrect (≈0-2ms)
---
1000ms = expected 2000ms - time to run previous sequential tests (5 * 100ms = 1000ms)
Looks like the a variable that stores start time is being reused by other tests and this causes incorrect durations.
test.concurrent is still somewhat experimental (the reason it's not documented), but a PR fixing it would be appreciated 🙂
It seems this is now working correctly, based on running the repl.it.
Seemingly most of the test events emitted by jest-circus are wrong for concurrent tests, as internally even though the original test is run concurrently, all events are fired and timing generated as if the tests run sequentially. Ref: https://github.com/facebook/jest/blob/master/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts#L89
Looks like the implementation of concurrency at least for the moment looks hackish, unfortunately (please don't take offense, it makes sense as it is still experimental). I guess it would require a bigger refactor within jest-circus to support concurrency properly, though I am not sure as my knowledge about the codebase is very slim. I Will have a look at this over the next few days
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.
This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
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.