Reduce default processor count to two under CI environments

Most CI implementations like travis / circleci run the builds
containerised. This can lead to the situartion where many more
processors are detected via /proc/cpuinfo and friends than are actually
usable through resource limits enforced by the containerization.
This can result in high resource consumption that might
result in abnormal build termination.

The default can easily be overriden in your CI setup.

* http://fabiokung.com/2014/03/13/memory-inside-linux-containers/
This commit is contained in:
Markus Schirp 2014-08-11 17:52:51 +00:00
parent c976dfb209
commit f633c8d894
3 changed files with 26 additions and 3 deletions

View file

@ -28,6 +28,16 @@ module Mutant
SCOPE_OPERATOR = '::'.freeze
# Test if CI is detected via environment
#
# @return [Boolean]
#
# @api private
#
def self.ci?
ENV.key?('CI')
end
# Lookup constant for location
#
# @param [String] location
@ -199,6 +209,8 @@ require 'mutant/zombifier/file'
module Mutant
# Reopen class to initialize constant to avoid dep circle
class Config
CI_DEFAULT_PROCESSOR_COUNT = 2
DEFAULT = new(
debug: false,
fail_fast: false,
@ -209,7 +221,7 @@ module Mutant
isolation: Mutant::Isolation::Fork,
reporter: Reporter::CLI.build($stdout),
zombie: false,
processes: Parallel.processor_count,
processes: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : Parallel.processor_count,
expected_coverage: 100.0
)
end # Config

View file

@ -13,10 +13,9 @@ module Mutant
# @api private
#
def self.build(output)
ci = ENV.key?('CI')
tty = output.respond_to?(:tty?) && output.tty?
format =
if !ci && tty && Tput::INSTANCE.available
if !Mutant.ci? && tty && Tput::INSTANCE.available
Format::Framed.new(tty: tty, tput: Tput::INSTANCE)
else
Format::Progressive.new(tty: tty)

View file

@ -1,6 +1,18 @@
RSpec.describe Mutant do
let(:object) { described_class }
describe '.ci?' do
subject { object.ci? }
let(:result) { double('Result') }
before do
expect(ENV).to receive(:key?).with('CI').and_return(result)
end
it { should be(result) }
end
describe '.zombify' do
subject { object.zombify }