From 3922c6da841871f010dcffb3fcbfffc48d49bdab Mon Sep 17 00:00:00 2001 From: Mark Lapierre Date: Mon, 3 Jun 2019 10:37:43 +0000 Subject: Generate knapsack report for review-qa-all Add knapsack qa report and use it to run tests in parallel Use the RSpec runner with knapsack The way the Knapsack runner uses exec to start rspec seems incompatible with the way we expect it to work. Plus, it requires specifying KNAPSACK_TEST_DIR. Instead, we use knapsacks AllocatorBuilder to select the spec files to run, and then start rspec as normal, via RSpec::Core::Runner.run This also means we can incorporate tags. Let the job run automatically Include KNAPSACK_TEST_FILE_PATTERN in vars Check all defined knapsack env vars before requiring knapsack --- qa/spec/runtime/env_spec.rb | 24 ++++++++++++++++++++++++ qa/spec/spec_helper.rb | 5 +++++ 2 files changed, 29 insertions(+) (limited to 'qa/spec') diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index 04085efe2ce..2560695ef2e 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -168,6 +168,30 @@ describe QA::Runtime::Env do end end + describe '.knapsack?' do + it 'returns true if KNAPSACK_GENERATE_REPORT is defined' do + stub_env('KNAPSACK_GENERATE_REPORT', 'true') + + expect(described_class.knapsack?).to be_truthy + end + + it 'returns true if KNAPSACK_REPORT_PATH is defined' do + stub_env('KNAPSACK_REPORT_PATH', '/a/path') + + expect(described_class.knapsack?).to be_truthy + end + + it 'returns true if KNAPSACK_TEST_FILE_PATTERN is defined' do + stub_env('KNAPSACK_TEST_FILE_PATTERN', '/a/**/pattern') + + expect(described_class.knapsack?).to be_truthy + end + + it 'returns false if neither KNAPSACK_GENERATE_REPORT nor KNAPSACK_REPORT_PATH nor KNAPSACK_TEST_FILE_PATTERN are defined' do + expect(described_class.knapsack?).to be_falsey + end + end + describe '.require_github_access_token!' do it 'raises ArgumentError if GITHUB_ACCESS_TOKEN is not defined' do stub_env('GITHUB_ACCESS_TOKEN', nil) diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb index a368ffba711..f25dbf3a8ab 100644 --- a/qa/spec/spec_helper.rb +++ b/qa/spec/spec_helper.rb @@ -3,6 +3,11 @@ require_relative '../qa' require 'rspec/retry' +if ENV['CI'] && QA::Runtime::Env.knapsack? && !ENV['NO_KNAPSACK'] + require 'knapsack' + Knapsack::Adapters::RSpecAdapter.bind +end + %w[helpers shared_examples].each do |d| Dir[::File.join(__dir__, d, '**', '*.rb')].each { |f| require f } end -- cgit v1.2.1