Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ export function createPool(ctx: Vitest): ProcessPool {
const groupedSpecifications: Record<string, TestSpecification[]> = {}
const groups = new Set<number>()

const factories: Record<LocalPool, () => ProcessPool> = {
vmThreads: () => createVmThreadsPool(ctx, options),
vmForks: () => createVmForksPool(ctx, options),
threads: () => createThreadsPool(ctx, options),
forks: () => createForksPool(ctx, options),
const factories: Record<LocalPool, (specs: TestSpecification[]) => ProcessPool> = {
vmThreads: specs => createVmThreadsPool(ctx, options, specs),
vmForks: specs => createVmForksPool(ctx, options, specs),
threads: specs => createThreadsPool(ctx, options, specs),
forks: specs => createForksPool(ctx, options, specs),
typescript: () => createTypecheckPool(ctx),
}

Expand Down Expand Up @@ -241,7 +241,7 @@ export function createPool(ctx: Vitest): ProcessPool {

if (pool in factories) {
const factory = factories[pool]
pools[pool] ??= factory()
pools[pool] ??= factory(specs)
return pools[pool]![method](specs, invalidate)
}

Expand Down
10 changes: 8 additions & 2 deletions packages/vitest/src/node/pools/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ContextRPC, ContextTestEnvironment } from '../../types/worker'
import type { Vitest } from '../core'
import type { PoolProcessOptions, ProcessPool, RunWithFiles } from '../pool'
import type { TestProject } from '../project'
import type { TestSpecification } from '../spec'
import type { SerializedConfig } from '../types/config'
import EventEmitter from 'node:events'
import * as nodeos from 'node:os'
Expand Down Expand Up @@ -65,6 +66,7 @@ function createChildProcessChannel(project: TestProject, collect = false) {
export function createForksPool(
vitest: Vitest,
{ execArgv, env }: PoolProcessOptions,
specifications: TestSpecification[],
): ProcessPool {
const numCpus
= typeof nodeos.availableParallelism === 'function'
Expand All @@ -75,12 +77,16 @@ export function createForksPool(
? Math.max(Math.floor(numCpus / 2), 1)
: Math.max(numCpus - 1, 1)

const recommendedCount = vitest.config.watch
? threadsCount
: Math.min(threadsCount, specifications.length)

const poolOptions = vitest.config.poolOptions?.forks ?? {}

const maxThreads
= poolOptions.maxForks ?? vitest.config.maxWorkers ?? threadsCount
= poolOptions.maxForks ?? vitest.config.maxWorkers ?? recommendedCount
const minThreads
= poolOptions.minForks ?? vitest.config.minWorkers ?? Math.min(threadsCount, maxThreads)
= poolOptions.minForks ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)

const worker = resolve(vitest.distPath, 'workers/forks.js')

Expand Down
10 changes: 8 additions & 2 deletions packages/vitest/src/node/pools/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ContextTestEnvironment } from '../../types/worker'
import type { Vitest } from '../core'
import type { PoolProcessOptions, ProcessPool, RunWithFiles } from '../pool'
import type { TestProject } from '../project'
import type { TestSpecification } from '../spec'
import type { SerializedConfig } from '../types/config'
import type { WorkerContext } from '../types/worker'
import * as nodeos from 'node:os'
Expand Down Expand Up @@ -46,6 +47,7 @@ function createWorkerChannel(project: TestProject, collect: boolean) {
export function createThreadsPool(
vitest: Vitest,
{ execArgv, env }: PoolProcessOptions,
specifications: TestSpecification[],
): ProcessPool {
const numCpus
= typeof nodeos.availableParallelism === 'function'
Expand All @@ -56,12 +58,16 @@ export function createThreadsPool(
? Math.max(Math.floor(numCpus / 2), 1)
: Math.max(numCpus - 1, 1)

const recommendedCount = vitest.config.watch
? threadsCount
: Math.min(threadsCount, specifications.length)

const poolOptions = vitest.config.poolOptions?.threads ?? {}

const maxThreads
= poolOptions.maxThreads ?? vitest.config.maxWorkers ?? threadsCount
= poolOptions.maxThreads ?? vitest.config.maxWorkers ?? recommendedCount
const minThreads
= poolOptions.minThreads ?? vitest.config.minWorkers ?? Math.min(threadsCount, maxThreads)
= poolOptions.minThreads ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)

const worker = resolve(vitest.distPath, 'workers/threads.js')

Expand Down
10 changes: 8 additions & 2 deletions packages/vitest/src/node/pools/vmForks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ContextRPC, ContextTestEnvironment } from '../../types/worker'
import type { Vitest } from '../core'
import type { PoolProcessOptions, ProcessPool, RunWithFiles } from '../pool'
import type { TestProject } from '../project'
import type { TestSpecification } from '../spec'
import type { ResolvedConfig, SerializedConfig } from '../types/config'
import EventEmitter from 'node:events'
import * as nodeos from 'node:os'
Expand Down Expand Up @@ -72,6 +73,7 @@ function createChildProcessChannel(project: TestProject, collect: boolean) {
export function createVmForksPool(
vitest: Vitest,
{ execArgv, env }: PoolProcessOptions,
specifications: TestSpecification[],
): ProcessPool {
const numCpus
= typeof nodeos.availableParallelism === 'function'
Expand All @@ -82,12 +84,16 @@ export function createVmForksPool(
? Math.max(Math.floor(numCpus / 2), 1)
: Math.max(numCpus - 1, 1)

const recommendedCount = vitest.config.watch
? threadsCount
: Math.min(threadsCount, specifications.length)

const poolOptions = vitest.config.poolOptions?.vmForks ?? {}

const maxThreads
= poolOptions.maxForks ?? vitest.config.maxWorkers ?? threadsCount
= poolOptions.maxForks ?? vitest.config.maxWorkers ?? recommendedCount
const minThreads
= poolOptions.maxForks ?? vitest.config.minWorkers ?? Math.min(threadsCount, maxThreads)
= poolOptions.maxForks ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)

const worker = resolve(vitest.distPath, 'workers/vmForks.js')

Expand Down
10 changes: 8 additions & 2 deletions packages/vitest/src/node/pools/vmThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ContextTestEnvironment } from '../../types/worker'
import type { Vitest } from '../core'
import type { PoolProcessOptions, ProcessPool, RunWithFiles } from '../pool'
import type { TestProject } from '../project'
import type { TestSpecification } from '../spec'
import type { ResolvedConfig, SerializedConfig } from '../types/config'
import type { WorkerContext } from '../types/worker'
import * as nodeos from 'node:os'
Expand Down Expand Up @@ -49,6 +50,7 @@ function createWorkerChannel(project: TestProject, collect: boolean) {
export function createVmThreadsPool(
vitest: Vitest,
{ execArgv, env }: PoolProcessOptions,
specifications: TestSpecification[],
): ProcessPool {
const numCpus
= typeof nodeos.availableParallelism === 'function'
Expand All @@ -59,12 +61,16 @@ export function createVmThreadsPool(
? Math.max(Math.floor(numCpus / 2), 1)
: Math.max(numCpus - 1, 1)

const recommendedCount = vitest.config.watch
? threadsCount
: Math.min(threadsCount, specifications.length)

const poolOptions = vitest.config.poolOptions?.vmThreads ?? {}

const maxThreads
= poolOptions.maxThreads ?? vitest.config.maxWorkers ?? threadsCount
= poolOptions.maxThreads ?? vitest.config.maxWorkers ?? recommendedCount
const minThreads
= poolOptions.minThreads ?? vitest.config.minWorkers ?? Math.min(threadsCount, maxThreads)
= poolOptions.minThreads ?? vitest.config.minWorkers ?? Math.min(recommendedCount, maxThreads)

const worker = resolve(vitest.distPath, 'workers/vmThreads.js')

Expand Down
Loading