From 3ffbc03457405be61cdc2f55a3a42e3078cd6649 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 2 Nov 2023 18:06:28 -0400 Subject: [PATCH] Use flatware to parallelize CI specs --- .github/workflows/test-ruby.yml | 6 ++++-- .simplecov | 2 ++ Gemfile | 3 +++ Gemfile.lock | 10 ++++++++++ bin/flatware | 27 +++++++++++++++++++++++++++ spec/flatware_helper.rb | 9 +++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100755 bin/flatware create mode 100644 spec/flatware_helper.rb diff --git a/.github/workflows/test-ruby.yml b/.github/workflows/test-ruby.yml index b28f5261c2e886..9bf4dfe7dd98c1 100644 --- a/.github/workflows/test-ruby.yml +++ b/.github/workflows/test-ruby.yml @@ -136,9 +136,11 @@ jobs: additional-system-dependencies: ffmpeg imagemagick libpam-dev - name: Load database schema - run: './bin/rails db:create db:schema:load db:seed' + run: | + bundle exec rake db:setup + bin/flatware fan rake db:test:prepare - - run: bin/rspec + - run: bin/flatware rspec -r ./spec/flatware_helper.rb - name: Upload coverage reports to Codecov if: matrix.ruby-version == '.ruby-version' diff --git a/.simplecov b/.simplecov index fbd0207bec51ce..436a45d2cf6637 100644 --- a/.simplecov +++ b/.simplecov @@ -9,6 +9,8 @@ else end SimpleCov.start 'rails' do + command_name "examples#{ENV.fetch('TEST_ENV_NUMBER', nil)}" + enable_coverage :branch add_filter 'lib/linter' diff --git a/Gemfile b/Gemfile index a10613b30b9fc9..0be5669e6d34d0 100644 --- a/Gemfile +++ b/Gemfile @@ -104,6 +104,9 @@ gem 'rdf-normalize', '~> 0.5' gem 'private_address_check', '~> 0.5' group :test do + # Enable usage of all available CPUs/cores during spec runs + gem 'flatware-rspec' + # Adds RSpec Error/Warning annotations to GitHub PRs on the Files tab gem 'rspec-github', '~> 2.4', require: false diff --git a/Gemfile.lock b/Gemfile.lock index d73de0320f6e2b..293f1d288574df 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -275,6 +275,11 @@ GEM ffi-compiler (1.3.2) ffi (>= 1.15.5) rake + flatware (2.2.1) + thor (< 2.0) + flatware-rspec (2.2.1) + flatware (= 2.2.1) + rspec (>= 3.6) fog-core (2.4.0) builder excon (~> 0.71) @@ -620,6 +625,10 @@ GEM chunky_png (~> 1.0) rqrcode_core (~> 1.0) rqrcode_core (1.2.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) rspec-core (3.13.0) rspec-support (~> 3.13.0) rspec-expectations (3.13.0) @@ -853,6 +862,7 @@ DEPENDENCIES faker (~> 3.2) fast_blank (~> 1.0) fastimage + flatware-rspec fog-core (<= 2.4.0) fog-openstack (~> 1.0) fuubar (~> 2.5) diff --git a/bin/flatware b/bin/flatware new file mode 100755 index 00000000000000..337ce9277e4687 --- /dev/null +++ b/bin/flatware @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'flatware' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("flatware", "flatware") diff --git a/spec/flatware_helper.rb b/spec/flatware_helper.rb new file mode 100644 index 00000000000000..52b17d85f33782 --- /dev/null +++ b/spec/flatware_helper.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +Flatware.configure do |config| + config.after_fork do |test_env_number| + unless ENV.fetch('DISABLE_SIMPLECOV', nil) == 'true' + SimpleCov.at_fork.call(test_env_number) # Combines parallel coverage results + end + end +end