@@ -11,6 +11,33 @@ task test: "test:isolated"
11
11
12
12
namespace :test do
13
13
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
+
14
41
dash_i = [
15
42
"test" ,
16
43
"lib" ,
@@ -39,13 +66,23 @@ namespace :test do
39
66
test_patterns = dirs . map { |dir | "test/#{ dir } /*_test.rb" }
40
67
test_files = Dir [ *test_patterns ] . select do |file |
41
68
!file . start_with? ( "test/fixtures/" ) && !file . start_with? ( "test/isolation/assets/" )
42
- end . sort
69
+ end
43
70
44
71
if ENV [ "BUILDKITE_PARALLEL_JOB_COUNT" ]
45
72
n = ENV [ "BUILDKITE_PARALLEL_JOB" ] . to_i
46
73
m = ENV [ "BUILDKITE_PARALLEL_JOB_COUNT" ] . to_i
47
74
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 ]
49
86
end
50
87
51
88
test_files . each do |file |
0 commit comments