Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-26 18:09:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-26 18:09:30 +0300
commit2eaa60e4555bb11ad5c0af905217f0fa61cf7cc9 (patch)
tree0b0096203355150802fb8f7f4fe208b41b5bed68 /tooling
parent142890d5bbefa7b1e1b30f263f9ad67d9d496d29 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/parallel_rspec19
-rw-r--r--tooling/lib/tooling/parallel_rspec_runner.rb78
2 files changed, 97 insertions, 0 deletions
diff --git a/tooling/bin/parallel_rspec b/tooling/bin/parallel_rspec
new file mode 100755
index 00000000000..a706df69a1e
--- /dev/null
+++ b/tooling/bin/parallel_rspec
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require 'optparse'
+require_relative '../lib/tooling/parallel_rspec_runner'
+
+options = {}
+
+OptionParser.new do |opts|
+ opts.on("--rspec_args rspec_args", String, "Optional rspec arguments") do |value|
+ options[:rspec_args] = value
+ end
+
+ opts.on("--filter filter_tests_file", String, "Optional filename containing tests to be filtered") do |value|
+ options[:filter_tests_file] = value
+ end
+end.parse!
+
+Tooling::ParallelRSpecRunner.run(options)
diff --git a/tooling/lib/tooling/parallel_rspec_runner.rb b/tooling/lib/tooling/parallel_rspec_runner.rb
new file mode 100644
index 00000000000..443da55a978
--- /dev/null
+++ b/tooling/lib/tooling/parallel_rspec_runner.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+require 'knapsack'
+
+# A custom parallel rspec runner based on Knapsack runner
+# which takes in additional option for a file containing
+# list of test files.
+#
+# When executing RSpec in CI, the list of tests allocated by Knapsack
+# will be compared with the test files listed in the file.
+#
+# Only the test files allocated by Knapsack and listed in the file
+# would be executed in the CI node.
+module Tooling
+ class ParallelRSpecRunner
+ def self.run(rspec_args: nil, filter_tests_file: nil)
+ new(rspec_args: rspec_args, filter_tests_file: filter_tests_file).run
+ end
+
+ def initialize(allocator: knapsack_allocator, filter_tests_file: nil, rspec_args: nil)
+ @allocator = allocator
+ @filter_tests_file = filter_tests_file
+ @rspec_args = rspec_args&.split(' ') || []
+ end
+
+ def run
+ Knapsack.logger.info
+ Knapsack.logger.info 'Knapsack node specs:'
+ Knapsack.logger.info node_tests
+ Knapsack.logger.info
+ Knapsack.logger.info 'Filter specs:'
+ Knapsack.logger.info filter_tests
+ Knapsack.logger.info
+ Knapsack.logger.info 'Running specs:'
+ Knapsack.logger.info tests_to_run
+ Knapsack.logger.info
+
+ exec(*rspec_command)
+ end
+
+ private
+
+ attr_reader :allocator, :filter_tests_file, :rspec_args
+
+ def rspec_command
+ %w[bundle exec rspec].tap do |cmd|
+ cmd.push(*rspec_args)
+ cmd.push('--default-path', allocator.test_dir)
+ cmd.push('--')
+ cmd.push(*tests_to_run)
+ end
+ end
+
+ def tests_to_run
+ return node_tests if filter_tests.empty?
+
+ node_tests & filter_tests
+ end
+
+ def node_tests
+ allocator.node_tests
+ end
+
+ def filter_tests
+ filter_tests_file ? tests_from_file(filter_tests_file) : []
+ end
+
+ def tests_from_file(filter_tests_file)
+ return [] unless File.exist?(filter_tests_file)
+
+ File.read(filter_tests_file).split(' ')
+ end
+
+ def knapsack_allocator
+ Knapsack::AllocatorBuilder.new(Knapsack::Adapters::RSpecAdapter).allocator
+ end
+ end
+end