Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for ordered test runs. #225

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ruby/lib/ci/queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Configuration
attr_accessor :timeout, :worker_id, :max_requeues, :grind_count, :failure_file, :export_flaky_tests_file
attr_accessor :requeue_tolerance, :namespace, :failing_test, :statsd_endpoint
attr_accessor :max_test_duration, :max_test_duration_percentile, :track_test_duration
attr_accessor :ordered_test_file
attr_accessor :max_test_failed, :redis_ttl
attr_reader :circuit_breakers
attr_writer :seed, :build_id
Expand All @@ -19,6 +20,7 @@ def from_env(env)
flaky_tests: load_flaky_tests(env['CI_QUEUE_FLAKY_TESTS']),
statsd_endpoint: env['CI_QUEUE_STATSD_ADDR'],
redis_ttl: env['CI_QUEUE_REDIS_TTL']&.to_i || 8 * 60 * 60,
ordered_test_file: env['CI_QUEUE_ORDERED_TEST_FILE'],
)
end

Expand All @@ -36,7 +38,7 @@ def initialize(
grind_count: nil, max_duration: nil, failure_file: nil, max_test_duration: nil,
max_test_duration_percentile: 0.5, track_test_duration: false, max_test_failed: nil,
queue_init_timeout: nil, redis_ttl: 8 * 60 * 60, report_timeout: nil, inactive_workers_timeout: nil,
export_flaky_tests_file: nil
export_flaky_tests_file: nil, ordered_test_file: nil
)
@build_id = build_id
@circuit_breakers = [CircuitBreaker::Disabled]
Expand All @@ -61,6 +63,7 @@ def initialize(
@report_timeout = report_timeout
@inactive_workers_timeout = inactive_workers_timeout
@export_flaky_tests_file = export_flaky_tests_file
@ordered_test_file = ordered_test_file
end

def queue_init_timeout
Expand Down Expand Up @@ -106,6 +109,10 @@ def build_id
def global_max_requeues(tests_count)
(tests_count * Float(requeue_tolerance)).ceil
end

def ordered_run?
!!ordered_test_file
end
end
end
end
11 changes: 10 additions & 1 deletion ruby/lib/ci/queue/redis/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ def distributed?

def populate(tests, random: Random.new)
@index = tests.map { |t| [t.id, t] }.to_h
tests = Queue.shuffle(tests, random)
if config.ordered_run?
tests = filter_and_sort(tests, config.ordered_test_file)
else
tests = Queue.shuffle(tests, random)
end
push(tests.map(&:id))
self
end

def filter_and_sort(tests, file_path)
file_lines = ::File.readlines(file_path).map(&:chomp)
tests.sort_by { |test| file_lines.index(test.id) || 999999 }.first(file_lines.length)
end

def populated?
!!defined?(@index)
end
Expand Down
10 changes: 10 additions & 0 deletions ruby/lib/minitest/queue/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,16 @@ def parser
opts.on('--failing-test TEST_IDENTIFIER') do |identifier|
queue_config.failing_test = identifier
end

help = <<~EOS
Specifies an ordered list of tests to be executed.
-Itest must be still specified with all test files to be loaded.
The format is Class#testname and it can be obtained from the artifacts tab in the specific CI build run to be simulated.
EOS
opts.on('--ordered-tests-file FILE', help) do |file|
queue_config.ordered_test_file = file
end

end
end

Expand Down
Loading