-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!(runner): support concurrent suites (#5491)
- Loading branch information
Showing
10 changed files
with
284 additions
and
7 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 { createDefer } from '@vitest/utils' | ||
import { describe, test, vi } from 'vitest' | ||
|
||
// 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/utils' | ||
|
||
// 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
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() | ||
}) | ||
}) | ||
} |