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

calculate unknwon runtime lazily ... also avoid .any? which checks ea… #750

Merged
merged 1 commit into from
Feb 15, 2020
Merged
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
16 changes: 11 additions & 5 deletions lib/parallel_tests/test/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,7 @@ def sort_by_runtime(tests, runtimes, options={})
puts "Runtime found for #{tests.count(&:last)} of #{tests.size} tests"
end

# fill gaps with unknown-runtime if given, average otherwise
known, unknown = tests.partition(&:last)
average = (known.any? ? known.map!(&:last).inject(:+) / known.size : 1)
unknown_runtime = options[:unknown_runtime] || average
unknown.each { |set| set[1] = unknown_runtime }
set_unknown_runtime tests, options
end

def runtimes(tests, options)
Expand Down Expand Up @@ -240,6 +236,16 @@ def files_in_folder(folder, options={})

private

# fill gaps with unknown-runtime if given, average otherwise
# NOTE: an optimization could be doing runtime by average runtime per file size, but would need file checks
def set_unknown_runtime(tests, options)
known, unknown = tests.partition(&:last)
return if unknown.empty?
unknown_runtime = options[:unknown_runtime] ||
(known.empty? ? 1 : known.map!(&:last).inject(:+) / known.size) # average
unknown.each { |set| set[1] = unknown_runtime }
end

def report_process_command?(options)
options[:verbose] || options[:verbose_process_command]
end
Expand Down