diff options
author | Bundlerbot <bot@bundler.io> | 2020-01-07 08:32:06 +0000 |
---|---|---|
committer | Bundlerbot <bot@bundler.io> | 2020-01-07 08:32:06 +0000 |
commit | 613bf9c4fbb462e8e5ddca418ba8f014f6e8e0dc (patch) | |
tree | 0869953ede86bd95daf4b46a20b1943f376ed881 | |
parent | b14ea22c7dbf18ec3fd36479afe549cb92efd203 (diff) | |
parent | 24350bf48d77dae3da0c8e168baaa4987af1c984 (diff) | |
download | bundler-613bf9c4fbb462e8e5ddca418ba8f014f6e8e0dc.tar.gz |
Merge #7550
7550: Enable parallel specs again r=deivid-rodriguez a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that specs are slow.
### What is your fix for the problem, implemented in this PR?
My fix is to run them in parallel.
We enabled this a while ago, but run into some issues. I want to try again.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
-rw-r--r-- | .github/workflows/windows.yml | 4 | ||||
-rw-r--r-- | .travis.yml | 9 | ||||
-rw-r--r-- | Rakefile | 53 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/rubygems_ext.rb | 50 |
5 files changed, 46 insertions, 71 deletions
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index f1538cff97..44c8039df6 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -25,10 +25,10 @@ jobs: ruby-version: ${{ matrix.ruby }} - name: Install dependencies - run: bin/rake spec:deps + run: bin/rake spec:parallel_deps shell: bash - name: Run specs - run: bin/rspec + run: bin/parallel_rspec spec shell: bash continue-on-error: true diff --git a/.travis.yml b/.travis.yml index a428231133..8fd329cf3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,15 @@ language: ruby dist: bionic -script: bin/rake spec:travis +script: + - bin/parallel_rspec spec + - sudo -E bin/rake spec:sudo + - sudo chown -R $(whoami) tmp + - BUNDLER_SPEC_PRE_RECORDED=1 bin/rake spec:realworld + before_script: - travis_retry gem install rake:"~> 12.0" - travis_retry bin/rake override_version - - travis_retry bin/rake spec:deps + - travis_retry bin/rake spec:parallel_deps - if [ "$BUNDLER_SPEC_SUB_VERSION" = "" ]; then travis_retry sudo apt-get install graphviz -y; @@ -24,20 +24,18 @@ task :spec do end namespace :spec do - def safe_task(&block) - yield - true - rescue StandardError - false - end - desc "Ensure spec dependencies are installed" task :deps do Spec::Rubygems.dev_setup + + Spec::Rubygems.install_test_deps end - task :clean do - rm_rf "tmp" + desc "Ensure spec dependencies for running in parallel are installed" + task :parallel_deps do + Spec::Rubygems.dev_setup + + Spec::Rubygems.install_parallel_test_deps end desc "Run the real-world spec suite" @@ -48,7 +46,7 @@ namespace :spec do task :record => %w[set_record realworld] task :set_record do - ENV["BUNDLER_SPEC_FORCE_RECORD"] = "TRUE" + ENV["BUNDLER_SPEC_FORCE_RECORD"] = "1" end end @@ -62,41 +60,6 @@ namespace :spec do task :set_sudo do ENV["BUNDLER_SUDO_TESTS"] = "1" end - - desc "Run the tests on Travis CI against a RubyGem version (using ENV['RGV'])" - task :travis do - rg = ENV["RGV"] || raise("RubyGems version is required on Travis!") - - # disallow making network requests on CI - ENV["BUNDLER_SPEC_PRE_RECORDED"] = "TRUE" - - puts "\n\e[1;33m[Travis CI] Running bundler specs against RubyGems #{rg}\e[m\n\n" - specs = safe_task { Rake::Task["spec"].invoke } - - Rake::Task["spec"].reenable - - puts "\n\e[1;33m[Travis CI] Running bundler sudo specs against RubyGems #{rg}\e[m\n\n" - sudos = system("sudo -E rake spec:sudo") - # clean up by chowning the newly root-owned tmp directory back to the travis user - system("sudo chown -R #{ENV["USER"]} #{File.join(File.dirname(__FILE__), "tmp")}") - - Rake::Task["spec"].reenable - - puts "\n\e[1;33m[Travis CI] Running bundler real world specs against RubyGems #{rg}\e[m\n\n" - realworld = safe_task { Rake::Task["spec:realworld"].invoke } - - { "specs" => specs, "sudo" => sudos, "realworld" => realworld }.each do |name, passed| - if passed - puts "\e[0;32m[Travis CI] #{name} passed\e[m" - else - puts "\e[0;31m[Travis CI] #{name} failed\e[m" - end - end - - unless specs && sudos && realworld - raise "Spec run failed, please review the log for more information" - end - end end desc "Run RuboCop" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4e99a6dd8..2b975cf5fc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,6 @@ require_relative "support/path" -$:.unshift Spec::Path.spec_dir.to_s $:.unshift Spec::Path.lib_dir.to_s require "bundler/psyched_yaml" diff --git a/spec/support/rubygems_ext.rb b/spec/support/rubygems_ext.rb index ee9c750a52..b9bbfde2b3 100644 --- a/spec/support/rubygems_ext.rb +++ b/spec/support/rubygems_ext.rb @@ -51,24 +51,9 @@ module Spec end def setup - require "fileutils" - - Gem.clear_paths - - ENV["BUNDLE_PATH"] = nil - ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s - ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + install_test_deps - manifest = DEPS.to_a.sort_by(&:first).map {|k, v| "#{k} => #{v}\n" } - manifest_path = Path.base_system_gems.join("manifest.txt") - # it's OK if there are extra gems - if !manifest_path.file? || !(manifest - manifest_path.readlines).empty? - FileUtils.rm_rf(Path.base_system_gems) - FileUtils.mkdir_p(Path.base_system_gems) - puts "installing gems for the tests to use..." - install_gems(DEPS) - manifest_path.open("wb") {|f| f << manifest.join } - end + require "fileutils" FileUtils.mkdir_p(Path.home) FileUtils.mkdir_p(Path.tmpdir) @@ -80,6 +65,32 @@ module Spec Gem::DefaultUserInteraction.ui = Gem::SilentUI.new end + def install_parallel_test_deps + require "parallel" + + prev_env_test_number = ENV["TEST_ENV_NUMBER"] + + begin + Parallel.processor_count.times do |n| + ENV["TEST_ENV_NUMBER"] = (n + 1).to_s + + install_test_deps + end + ensure + ENV["TEST_ENV_NUMBER"] = prev_env_test_number + end + end + + def install_test_deps + Gem.clear_paths + + ENV["BUNDLE_PATH"] = nil + ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s + ENV["PATH"] = [Path.bindir, Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR) + + install_gems(DEPS) + end + private def gem_load_and_activate(gem_name, bin_container) @@ -95,10 +106,7 @@ module Spec end def install_gems(gems) - reqs, no_reqs = gems.partition {|_, req| !req.nil? && !req.split(" ").empty? } - no_reqs.map!(&:first) - reqs.map! {|name, req| "'#{name}:#{req}'" } - deps = reqs.concat(no_reqs).join(" ") + deps = gems.map {|name, req| "'#{name}:#{req}'" }.join(" ") gem = ENV["GEM_COMMAND"] || "#{Gem.ruby} -S gem --backtrace" cmd = "#{gem} install #{deps} --no-document --conservative" system(cmd) || raise("Installing gems #{deps} for the tests to use failed!") |