@@ -14,20 +14,19 @@ def self.run(opts = {})
1414 formatters = opts [ :formatters ]
1515 tags = opts [ :tags ]
1616
17- # SEE: https://bit.ly/2NP87Cz
18- start_time = opts . fetch ( :start_time ) { Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) }
17+ start_time = opts . fetch ( :start_time ) { RSpec ::Core ::Time . now }
1918 runtime_log = opts . fetch ( :runtime_log , nil )
2019 verbose = opts . fetch ( :verbose , false )
2120 fail_fast = opts . fetch ( :fail_fast , nil )
2221 count = opts . fetch ( :count , nil )
23- seed = opts . fetch ( :seed ) || rand ( 0xFFFF ) . to_s
24- seed_used = !opts [ : seed] . nil?
22+ seed = opts . fetch ( :seed )
23+ seed_used = !seed . nil?
2524
2625 if verbose
2726 STDERR . puts "VERBOSE"
2827 end
2928
30- reporter = Reporter . from_config ( formatters , start_time )
29+ reporter = Reporter . from_config ( formatters , start_time , seed , seed_used )
3130
3231 new (
3332 reporter : reporter ,
@@ -38,7 +37,7 @@ def self.run(opts = {})
3837 fail_fast : fail_fast ,
3938 count : count ,
4039 seed : seed ,
41- seed_used : seed_used
40+ seed_used : seed_used ,
4241 ) . run
4342 end
4443
@@ -50,11 +49,12 @@ def initialize(opts)
5049 @verbose = opts [ :verbose ]
5150 @fail_fast = opts [ :fail_fast ]
5251 @count = opts [ :count ]
52+ @seed = opts [ :seed ]
53+ @seed_used = opts [ :seed_used ]
54+
5355 @load_time = 0
5456 @load_count = 0
5557 @failure_count = 0
56- @seed = opts [ :seed ]
57- @seed_used = opts [ :seed_used ]
5858
5959 @messages = Thread ::Queue . new
6060 @threads = [ ]
@@ -87,26 +87,25 @@ def run
8787 setup_tmp_dir
8888
8989 subprocess_opts = {
90- record_runtime : use_runtime_info
90+ record_runtime : use_runtime_info ,
9191 }
9292
93- report_number_of_tests ( tests_in_groups )
94-
95- @reporter . seed_notification ( @seed , @seed_used )
96-
97- wait_threads = tests_in_groups . map . with_index do |tests , process_id |
98- start_regular_subprocess ( tests , process_id + 1 , **subprocess_opts )
99- end
100-
101- handle_messages
102-
103- @reporter . finish
93+ @reporter . report ( tests_in_groups ) do |reporter |
94+ wait_threads = tests_in_groups . map . with_index do |tests , process_id |
95+ start_regular_subprocess ( tests , process_id + 1 , **subprocess_opts )
96+ end
10497
105- @reporter . seed_notification ( @seed , @seed_used )
98+ handle_messages
10699
107- @threads . each ( &:join )
100+ @threads . each ( &:join )
108101
109- @reporter . failed_examples . empty? && wait_threads . map ( &:value ) . all? ( &:success? )
102+ if @reporter . failed_examples . empty? && wait_threads . map ( &:value ) . all? ( &:success? )
103+ 0
104+ else
105+ # From https://github.com/serpapi/turbo_tests/pull/20/
106+ wait_threads . map { |thread | thread . value . exitstatus } . max
107+ end
108+ end
110109 end
111110
112111 private
@@ -157,10 +156,18 @@ def start_subprocess(env, extra_args, tests, process_id, record_runtime:)
157156 [ ]
158157 end
159158
159+ seed_option = if @seed_used
160+ [
161+ "--seed" , @seed ,
162+ ]
163+ else
164+ [ ]
165+ end
166+
160167 command = [
161168 "rspec" ,
162169 *extra_args ,
163- "--seed" , @seed ,
170+ * seed_option ,
164171 "--format" , "TurboTests::JsonRowsFormatter" ,
165172 "--out" , tmp_filename ,
166173 *record_runtime_options ,
@@ -273,15 +280,5 @@ def handle_messages
273280 def fail_fast_met
274281 !@fail_fast . nil? && @failure_count >= @fail_fast
275282 end
276-
277- def report_number_of_tests ( groups )
278- name = ParallelTests ::RSpec ::Runner . test_file_name
279-
280- num_processes = groups . size
281- num_tests = groups . map ( &:size ) . sum
282- tests_per_process = ( num_processes == 0 ? 0 : num_tests . to_f / num_processes ) . round
283-
284- puts "#{ num_processes } processes for #{ num_tests } #{ name } s, ~ #{ tests_per_process } #{ name } s per process"
285- end
286283 end
287284end
0 commit comments