-
Notifications
You must be signed in to change notification settings - Fork 95
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
Sorting Algorithm: round robin to least connections #99
Sorting Algorithm: round robin to least connections #99
Conversation
TODO: remove > ruby 1.9.3 features |
end | ||
|
||
def sorted_report_with_existing_tests | ||
@sorted_report_with_existing_tests ||= sorted_report.select { |test_path, time| all_tests.include?(test_path) } | ||
end | ||
|
||
def total_time_execution | ||
@total_time_execution ||= sorted_report_with_existing_tests.map(&:last).reduce(0, :+).to_f | ||
@total_time_execution ||= sorted_report_with_existing_tests.sum { |_test_path, time| time }.to_f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change this line because sum
method in not available in Ruby <= 2.3 and it was breaking CI build.
Here is the fix 0be9583
y[1] <=> x[1] | ||
end | ||
node_tests.map do |node| | ||
node[:test_files_with_time].sort_by! { |file_name, _time| -file_name } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will keep reverse!
96476a5 because sorting file_name
string with -
char does not work in Ruby 2.2 https://github.com/KnapsackPro/knapsack/runs/2896841914?check_suite_focus=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using reverse!
should not have a big impact on performance and it's more readable than using -
char.
https://stackoverflow.com/questions/2642182/how-to-sort-an-array-in-descending-order-in-ruby
Thanks @prostko for the PR. I've released knapsack 3.1.0 version. |
references #98
Changes the Round Robin approach to a Least Connections approach.
Changes:
.sort.reverse
s with a sort_by { |x| -x } for readability and terseness:weight
key to default nodes