-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat!(runner): support concurrent suites #5491
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2597cd6
feat: support running suites in parallel
hi-ogawa de4fe6c
chore: cleanup
hi-ogawa f409f80
test: add test
hi-ogawa 89aadc6
chore: cleanup
hi-ogawa 7b3ffeb
test: test with describe.each
hi-ogawa 060a3ab
test: tweak
hi-ogawa 71bfabd
test: more
hi-ogawa 247ca42
test: tweak
hi-ogawa 9dee912
test: test maxConcurrency
hi-ogawa 6264d10
Merge branch 'main' into feat-concurrent-suite
hi-ogawa f52316b
wip: limitMaxConcurrency only test cases
hi-ogawa ee0373a
Merge branch 'main' into feat-concurrent-suite
hi-ogawa 7bb58da
chore: remove concurrentSuite and use only concurrent
hi-ogawa 029a1cd
test: test override `concurrent: false`
hi-ogawa 7454aea
test: describe.sequential
hi-ogawa 0e071e0
chore(docs): update describe.concurrent
hi-ogawa 5ede155
chore: fix createDefer
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { describe, test, vi } from 'vitest' | ||
import { createDefer } from 'vitest/dist/utils.js' | ||
|
||
// 3 tests depend on each other, | ||
// so they will deadlock when maxConcurrency < 3 | ||
// | ||
// [a] [b] [c] | ||
// * -> | ||
// * -> | ||
// <- * | ||
// <------ | ||
|
||
vi.setConfig({ maxConcurrency: 2 }) | ||
|
||
describe('wrapper', { concurrent: true, timeout: 500 }, () => { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
describe('1st suite', () => { | ||
test('a', async () => { | ||
defers[0].resolve() | ||
await defers[2] | ||
}) | ||
|
||
test('b', async () => { | ||
await defers[0] | ||
defers[1].resolve() | ||
await defers[2] | ||
}) | ||
}) | ||
|
||
describe('2nd suite', () => { | ||
test('c', async () => { | ||
await defers[1] | ||
defers[2].resolve() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { describe, test, vi } from 'vitest' | ||
import { createDefer } from 'vitest/dist/utils.js' | ||
|
||
// 3 tests depend on each other, | ||
// so they will deadlock when maxConcurrency < 3 | ||
// | ||
// [a] [b] [c] | ||
// * -> | ||
// * -> | ||
// <- * | ||
// <------ | ||
|
||
vi.setConfig({ maxConcurrency: 2 }) | ||
|
||
describe('wrapper', { concurrent: true, timeout: 500 }, () => { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
test('a', async () => { | ||
defers[0].resolve() | ||
await defers[2] | ||
}) | ||
|
||
test('b', async () => { | ||
await defers[0] | ||
defers[1].resolve() | ||
await defers[2] | ||
}) | ||
|
||
test('c', async () => { | ||
await defers[1] | ||
defers[2].resolve() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import { createDefer } from '@vitest/utils' | ||
import { afterAll, describe, expect, test } from 'vitest' | ||
|
||
describe('basic', () => { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
afterAll(async () => { | ||
await defers[3] | ||
}) | ||
|
||
describe('1st suite', { concurrent: true }, () => { | ||
test('0', async () => { | ||
defers[0].resolve() | ||
}) | ||
|
||
test('1', async () => { | ||
await defers[2] // this would deadlock if sequential | ||
defers[1].resolve() | ||
}) | ||
}) | ||
|
||
describe('2nd suite', { concurrent: true }, () => { | ||
test('2', async () => { | ||
await defers[0] | ||
defers[2].resolve() | ||
}) | ||
test('3', async () => { | ||
await defers[1] | ||
defers[3].resolve() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('inherits option', { concurrent: true }, () => { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
afterAll(async () => { | ||
await defers[3] | ||
}) | ||
|
||
describe('1st suite', () => { | ||
test('0', async () => { | ||
defers[0].resolve() | ||
}) | ||
|
||
test('1', async () => { | ||
await defers[2] // this would deadlock if sequential | ||
defers[1].resolve() | ||
}) | ||
}) | ||
|
||
describe('2nd suite', () => { | ||
test('2', async () => { | ||
await defers[0] | ||
defers[2].resolve() | ||
}) | ||
test('3', async () => { | ||
await defers[1] | ||
defers[3].resolve() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('works with describe.each', () => { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
afterAll(async () => { | ||
await defers[3] | ||
}) | ||
|
||
describe.each(['1st suite', '2nd suite'])('%s', { concurrent: true }, (s) => { | ||
if (s === '1st suite') { | ||
test('0', async () => { | ||
defers[0].resolve() | ||
}) | ||
|
||
test('1', async () => { | ||
await defers[2] // this would deadlock if sequential | ||
defers[1].resolve() | ||
}) | ||
} | ||
|
||
if (s === '2nd suite') { | ||
test('2', async () => { | ||
await defers[0] | ||
defers[2].resolve() | ||
}) | ||
test('3', async () => { | ||
await defers[1] | ||
defers[3].resolve() | ||
}) | ||
} | ||
}) | ||
}) | ||
|
||
describe('override concurrent', { concurrent: true }, () => { | ||
checkParallelSuites() | ||
|
||
describe('s-x', { concurrent: false }, () => { | ||
checkSequentialTests() | ||
}) | ||
|
||
describe.sequential('s-x-1', () => { | ||
checkSequentialTests() | ||
}) | ||
|
||
// TODO: not working? | ||
// describe('s-x-2', { sequential: true, }, () => { | ||
// checkSequentialTests() | ||
// }) | ||
|
||
describe('s-y', () => { | ||
checkParallelTests() | ||
}) | ||
}) | ||
|
||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
function checkSequentialTests() { | ||
let x = 0 | ||
|
||
test('t1', async () => { | ||
await sleep(200) | ||
expect(x).toBe(0) | ||
x++ | ||
}) | ||
|
||
test('t2', async () => { | ||
expect(x).toBe(1) | ||
}) | ||
} | ||
|
||
function checkParallelTests() { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
test('t1', async () => { | ||
defers[0].resolve() | ||
await defers[1] | ||
}) | ||
|
||
test('t2', async () => { | ||
await defers[0] | ||
defers[1].resolve() | ||
}) | ||
} | ||
|
||
function checkParallelSuites() { | ||
const defers = [ | ||
createDefer<void>(), | ||
createDefer<void>(), | ||
] | ||
|
||
describe('s1', () => { | ||
test('t1', async () => { | ||
defers[0].resolve() | ||
await defers[1] | ||
}) | ||
}) | ||
|
||
describe('s2', () => { | ||
test('t1', async () => { | ||
await defers[0] | ||
defers[1].resolve() | ||
}) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it importing from dist 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I didn't notice but it seems typescript got that one from autocomplete.
I installed
@vitest/utils
and it looks okay now.