Skip to content

Commit 3f81fc4

Browse files
lukechildsnovemberborn
authored andcommitted
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.
1 parent 1cb9d4f commit 3f81fc4

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const os = require('os');
66
const commonPathPrefix = require('common-path-prefix');
77
const uniqueTempDir = require('unique-temp-dir');
88
const findCacheDir = require('find-cache-dir');
9+
const isCi = require('is-ci');
910
const resolveCwd = require('resolve-cwd');
1011
const debounce = require('lodash.debounce');
1112
const autoBind = require('auto-bind');
@@ -161,7 +162,7 @@ class Api extends EventEmitter {
161162
this._setupTimeout(runStatus);
162163
}
163164

164-
let concurrency = os.cpus().length;
165+
let concurrency = Math.min(os.cpus().length, isCi ? 2 : Infinity);
165166

166167
if (this.options.concurrency > 0) {
167168
concurrency = this.options.concurrency;

docs/common-pitfalls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AVA uses [is-ci](https://github.com/watson/is-ci) to decide if it's in a CI envi
1616

1717
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.
1818

19-
By default, AVA will use as many processes as there are CPU cores in your machine.
19+
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.
2020

2121
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.
2222

0 commit comments

Comments
 (0)