Permalink
Browse files

Limit concurrency to 2 in a CI environment

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 3f81fc431016ca115177d2d79cf9db36b05f69ad
Showing with 3 additions and 2 deletions.
  1. +2 −1 api.js
  2. +1 −1 docs/common-pitfalls.md
View
3 api.js
@@ -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');
@@ -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;
View
@@ -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.

0 comments on commit 3f81fc4

Please sign in to comment.