|
| 1 | +import type { PoolOptions, ResolvedConfig } from 'vitest/node' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { getWorkerMemoryLimit } from 'vitest/src/utils/memory-limit.js' |
| 4 | + |
| 5 | +function makeConfig(poolOptions: PoolOptions): ResolvedConfig { |
| 6 | + return { |
| 7 | + poolOptions: { |
| 8 | + vmForks: { |
| 9 | + maxForks: poolOptions.maxForks, |
| 10 | + memoryLimit: poolOptions.memoryLimit, |
| 11 | + }, |
| 12 | + vmThreads: { |
| 13 | + maxThreads: poolOptions.maxThreads, |
| 14 | + memoryLimit: poolOptions.memoryLimit, |
| 15 | + }, |
| 16 | + }, |
| 17 | + } as ResolvedConfig |
| 18 | +} |
| 19 | + |
| 20 | +describe('getWorkerMemoryLimit', () => { |
| 21 | + it('should prioritize vmThreads.memoryLimit when pool is vmThreads', () => { |
| 22 | + const config = { |
| 23 | + poolOptions: { |
| 24 | + vmForks: { memoryLimit: undefined }, |
| 25 | + vmThreads: { memoryLimit: '256MB' }, |
| 26 | + }, |
| 27 | + } as ResolvedConfig |
| 28 | + |
| 29 | + expect(getWorkerMemoryLimit(config, 'vmThreads')).toBe('256MB') |
| 30 | + }) |
| 31 | + |
| 32 | + it('should prioritize vmForks.memoryLimit when pool is vmForks', () => { |
| 33 | + const config = makeConfig({ memoryLimit: '512MB' }) |
| 34 | + expect(getWorkerMemoryLimit(config, 'vmForks')).toBe('512MB') |
| 35 | + }) |
| 36 | + |
| 37 | + it('should calculate 1/maxThreads when vmThreads.memoryLimit is unset', () => { |
| 38 | + const config = makeConfig({ maxThreads: 4 }) |
| 39 | + expect(getWorkerMemoryLimit(config, 'vmThreads')).toBe(1 / 4) |
| 40 | + }) |
| 41 | + |
| 42 | + it('should calculate 1/maxForks when vmForks.memoryLimit is unset', () => { |
| 43 | + const config = makeConfig({ maxForks: 4 }) |
| 44 | + expect(getWorkerMemoryLimit(config, 'vmForks')).toBe(1 / 4) |
| 45 | + }) |
| 46 | +}) |
0 commit comments