Skip to content

Commit 58a316b

Browse files
jdelStrotherbriandunn
authored andcommitted
Improve job-distribution with a mix of timed & untimed files
1 parent 455b61c commit 58a316b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/flatware/rspec/job_builder.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ def jobs
4343
private
4444

4545
def balance_jobs(bucket_count:, timed_files:, untimed_files:)
46-
balance_by(bucket_count, timed_files, &:last)
47-
.map { |bucket| bucket.map(&:first) }
48-
.zip(
49-
round_robin(bucket_count, untimed_files)
50-
).map(&:flatten)
46+
timed_groups = balance_by(bucket_count, timed_files, &:last)
47+
.map { |bucket| bucket.map(&:first) }
48+
untimed_groups = round_robin(bucket_count, untimed_files)
49+
50+
# When the files can't be evenly divided between groups, the first groups
51+
# in each of timed_groups & untimed_groups will have more files.
52+
# By reversing one of them before combining them, we can improve the final distribution.
53+
timed_groups
54+
.zip(untimed_groups.reverse)
55+
.map(&:flatten)
5156
.reject(&:empty?)
5257
.map { |files| Job.new(files, args) }
5358
end

spec/flatware/rspec/job_builder_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@
8080
it "doesn't return empty job-groups" do
8181
expect(subject).to match_array(
8282
[
83-
have_attributes(id: include('./slow_spec.rb', './new_1_spec.rb')),
84-
have_attributes(id: include('./fast_1_spec.rb'))
83+
have_attributes(id: include('./fast_1_spec.rb')),
84+
have_attributes(id: include('./slow_spec.rb')),
85+
have_attributes(id: include('./new_1_spec.rb'))
8586
]
8687
)
8788
end

0 commit comments

Comments
 (0)