From f633c8d894e3a7d9710e26c24c615171ec14e328 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 11 Aug 2014 17:52:51 +0000 Subject: [PATCH] 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/ --- lib/mutant.rb | 14 +++++++++++++- lib/mutant/reporter/cli.rb | 3 +-- spec/unit/mutant_spec.rb | 12 ++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/mutant.rb b/lib/mutant.rb index 095dc319..267dfc1b 100644 --- a/lib/mutant.rb +++ b/lib/mutant.rb @@ -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 diff --git a/lib/mutant/reporter/cli.rb b/lib/mutant/reporter/cli.rb index 14ec28f7..ac4961be 100644 --- a/lib/mutant/reporter/cli.rb +++ b/lib/mutant/reporter/cli.rb @@ -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) diff --git a/spec/unit/mutant_spec.rb b/spec/unit/mutant_spec.rb index 0abd0ca2..60066fd3 100644 --- a/spec/unit/mutant_spec.rb +++ b/spec/unit/mutant_spec.rb @@ -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 }