Skip to content

Commit

Permalink
Limit concurrency to 2 in a CI environment
Browse files Browse the repository at this point in the history
CI environments may falsely represent the number of logical cores available, especially if they run inside a Docker container. Cap at 2 to prevent overwhelming the cores that are actually available.
  • Loading branch information
lukechilds authored and novemberborn committed Oct 24, 2017
1 parent 1cb9d4f commit 3f81fc4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api.js
Expand Up @@ -6,6 +6,7 @@ const os = require('os');
const commonPathPrefix = require('common-path-prefix');
const uniqueTempDir = require('unique-temp-dir');
const findCacheDir = require('find-cache-dir');
const isCi = require('is-ci');
const resolveCwd = require('resolve-cwd');
const debounce = require('lodash.debounce');
const autoBind = require('auto-bind');
Expand Down Expand Up @@ -161,7 +162,7 @@ class Api extends EventEmitter {
this._setupTimeout(runStatus);
}

let concurrency = os.cpus().length;
let concurrency = Math.min(os.cpus().length, isCi ? 2 : Infinity);

if (this.options.concurrency > 0) {
concurrency = this.options.concurrency;
Expand Down
2 changes: 1 addition & 1 deletion docs/common-pitfalls.md
Expand Up @@ -16,7 +16,7 @@ AVA uses [is-ci](https://github.com/watson/is-ci) to decide if it's in a CI envi

You may be using a service that only allows a limited number of concurrent connections. For example, many database-as-a-service businesses offer a free plan with a limit on how many clients can be using it at the same time. AVA can hit those limits as it runs multiple processes, but well-written services should emit an error or throttle in those cases. If the one you're using doesn't, the tests will hang.

By default, AVA will use as many processes as there are CPU cores in your machine.
By default, AVA will use as many processes as there are [logical cores](https://superuser.com/questions/1105654/logical-vs-physical-cpu-performance) on your machine. This is capped at two in a CI environment.

Use the `concurrency` flag to limit the number of processes ran. For example, if your service plan allows 5 clients, you should run AVA with `concurrency=5` or less.

Expand Down

0 comments on commit 3f81fc4

Please sign in to comment.