Skip to content

Commit

Permalink
test: test maxConcurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 5, 2024
1 parent 247ca42 commit 9dee912
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
1 change: 0 additions & 1 deletion packages/runner/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export async function runSuite(suite: Suite, runner: VitestRunner) {
else {
for (let tasksGroup of partitionSuiteChildren(suite)) {
if (tasksGroup[0].concurrent === true) {
// TODO: p-limit needs to be shared globally to not go over maxConcurrency?
const mutex = limit(runner.config.maxConcurrency)
await Promise.all(tasksGroup.map(c => mutex(() => runSuiteChild(c, runner))))
}
Expand Down
42 changes: 42 additions & 0 deletions test/core/test/concurrent-maxConcurrency.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createDefer } from '@vitest/utils'
import { describe, test, vi } from 'vitest'

vi.setConfig({ maxConcurrency: 2 })

describe('limit for each suite', () => {
// this test requires running 3 tests in parallel.
// but, currently p-limit is applied for each suite layer,
// so tests succeed.
//
// [0] [1] [2]
// * ->
// * ->
// <- *
// <------

const defers = [
createDefer<void>(),
createDefer<void>(),
createDefer<void>(),
]

describe('1st suite', { concurrent: true, concurrentSuite: true }, () => {
test('a', async () => {
defers[0].resolve()
await defers[2]
})

test('b', async () => {
await defers[0]
defers[1].resolve()
await defers[2]
})
})

describe('2nd suite', { concurrent: true, concurrentSuite: true }, () => {
test('c', async () => {
await defers[1]
defers[2].resolve()
})
})
})
34 changes: 0 additions & 34 deletions test/core/test/concurrent-suite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,37 +129,3 @@ describe('tests are sequential', () => {
})
})
})

// TODO
describe('maxConcurrency', { concurrent: true, concurrentSuite: true }, () => {
const defers = [
createDefer<void>(),
createDefer<void>(),
createDefer<void>(),
createDefer<void>(),
]

describe('1st suite', () => {
test('0', async () => {
defers[0].resolve()
await defers[3]
})

test('1', async () => {
await defers[0]
defers[1].resolve()
})
})

describe('2nd suite', () => {
test('2', async () => {
await defers[1]
defers[2].resolve()
})

test('3', async () => {
await defers[2]
defers[3].resolve()
})
})
})

0 comments on commit 9dee912

Please sign in to comment.