Skip to content

fix: don't crash when memoryLimit is assumed to be a percentage of system memory#4802

Merged
AriPerkkio merged 3 commits intovitest-dev:mainfrom
inottn:fix/memory-limit
Jan 1, 2024
Merged

fix: don't crash when memoryLimit is assumed to be a percentage of system memory#4802
AriPerkkio merged 3 commits intovitest-dev:mainfrom
inottn:fix/memory-limit

Conversation

@inottn
Copy link
Contributor

@inottn inottn commented Dec 24, 2023

Description

When I upgraded vitest to version 1.1.0 and replaced the original experimentalVmWorkerMemoryLimit config with poolOptions.vmThreads.memoryLimit, an error occurred when running pnpm test: "For a percentage based memory limit, a percentageReference must be provided."

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link

netlify bot commented Dec 24, 2023

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit e0877c2
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/6592c97a2732390008708513

@sheremet-va
Copy link
Member

When I upgraded vitest to version 1.1.0 and replaced the original experimentalVmWorkerMemoryLimit config with poolOptions.vmThreads.memoryLimit, an error occurred when running pnpm test: "For a percentage based memory limit, a percentageReference must be provided."

Can you give an example of a value that throws an error here?

@inottn
Copy link
Contributor Author

inottn commented Dec 28, 2023

I'm sorry for not providing a specific example in the description earlier.

Here is an example that throws an error when memoryLimit is less than 1.

import { cpus } from 'os';
import { defineConfig } from 'vitest/config';

const cpuNum = Math.max(cpus().length - 1, 1);

export default defineConfig({
  test: {
    // ...other config
    pool: 'vmThreads',
    poolOptions: {
      vmThreads: {
        memoryLimit: Math.min(1 / (cpuNum * 2), 0.1),
      },
    },
  },
});

@AriPerkkio
Copy link
Member

I can reproduce the crash. But now that I'm looking at function getMemoryLimit I can't remember all parts of its implementation. 😅

I'll need to do some more debugging and testing before we can merge this.

Copy link
Member

@AriPerkkio AriPerkkio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@AriPerkkio AriPerkkio merged commit 70e8a38 into vitest-dev:main Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants