Skip to content

Commit 483d0dc

Browse files
committed
Better spread out the railties tests
1 parent 249f2f3 commit 483d0dc

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

railties/Rakefile

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ task test: "test:isolated"
1111

1212
namespace :test do
1313
task :isolated do
14+
estimated_duration = {
15+
"test/application/test_runner_test.rb" => 201,
16+
"test/application/assets_test.rb" => 131,
17+
"test/application/rake/migrations_test.rb" => 65,
18+
"test/generators/scaffold_generator_test.rb" => 57,
19+
"test/generators/plugin_test_runner_test.rb" => 57,
20+
"test/application/test_test.rb" => 52,
21+
"test/application/configuration_test.rb" => 49,
22+
"test/generators/app_generator_test.rb" => 43,
23+
"test/application/rake/dbs_test.rb" => 43,
24+
"test/application/rake_test.rb" => 33,
25+
"test/generators/plugin_generator_test.rb" => 30,
26+
"test/railties/engine_test.rb" => 27,
27+
"test/generators/scaffold_controller_generator_test.rb" => 23,
28+
"test/railties/generators_test.rb" => 19,
29+
"test/application/console_test.rb" => 16,
30+
"test/engine/commands_test.rb" => 15,
31+
"test/application/routing_test.rb" => 15,
32+
"test/application/mailer_previews_test.rb" => 15,
33+
"test/application/rake/multi_dbs_test.rb" => 13,
34+
"test/application/asset_debugging_test.rb" => 12,
35+
"test/application/bin_setup_test.rb" => 11,
36+
"test/engine/test_test.rb" => 10,
37+
"test/application/runner_test.rb" => 10,
38+
}
39+
estimated_duration.default = 1
40+
1441
dash_i = [
1542
"test",
1643
"lib",
@@ -39,13 +66,23 @@ namespace :test do
3966
test_patterns = dirs.map { |dir| "test/#{dir}/*_test.rb" }
4067
test_files = Dir[*test_patterns].select do |file|
4168
!file.start_with?("test/fixtures/") && !file.start_with?("test/isolation/assets/")
42-
end.sort
69+
end
4370

4471
if ENV["BUILDKITE_PARALLEL_JOB_COUNT"]
4572
n = ENV["BUILDKITE_PARALLEL_JOB"].to_i
4673
m = ENV["BUILDKITE_PARALLEL_JOB_COUNT"].to_i
4774

48-
test_files = test_files.each_slice(m).map { |slice| slice[n] }.compact
75+
buckets = Array.new(m) { [] }
76+
allocations = Array.new(m) { 0 }
77+
test_files.sort_by { |file| [-estimated_duration[file], file] }.each do |file|
78+
idx = allocations.index(allocations.min)
79+
buckets[idx] << file
80+
allocations[idx] += estimated_duration[file]
81+
end
82+
83+
puts "Running #{buckets[n].size} of #{test_files.size} test files, estimated duration #{allocations[n]}s"
84+
85+
test_files = buckets[n]
4986
end
5087

5188
test_files.each do |file|

0 commit comments

Comments
 (0)