@@ -74,6 +74,10 @@ def run_command
74
74
TestDataReporter . new ( namespace : queue_config &.namespace ) ,
75
75
OrderReporter . new ( path : 'log/test_order.log' ) ,
76
76
]
77
+ if queue_config . track_test_duration
78
+ test_time_record = CI ::Queue ::Redis ::TestTimeRecord . new ( queue_url , queue_config )
79
+ reporters << TestTimeRecorder . new ( build : test_time_record )
80
+ end
77
81
if queue_config . statsd_endpoint
78
82
reporters << Minitest ::Reporters ::StatsdReporter . new ( statsd_endpoint : queue_config . statsd_endpoint )
79
83
end
@@ -218,8 +222,23 @@ def report_command
218
222
File . write ( queue_config . export_flaky_tests_file , failures )
219
223
end
220
224
225
+ # Handle timing data reporting and export
226
+ test_time_reporter_success = if queue_config . track_test_duration
227
+ test_time_record = CI ::Queue ::Redis ::TestTimeRecord . new ( queue_url , queue_config )
228
+ test_time_reporter = TestTimeReporter . new (
229
+ build : test_time_record ,
230
+ limit : queue_config . max_test_duration ,
231
+ percentile : queue_config . max_test_duration_percentile ,
232
+ export_file : queue_config . export_timing_file
233
+ )
234
+ test_time_reporter . report
235
+ test_time_reporter . success?
236
+ else
237
+ true
238
+ end
239
+
221
240
reporter . report
222
- exit! reporter . success? ? 0 : 1
241
+ exit! reporter . success? && test_time_reporter_success ? 0 : 1
223
242
end
224
243
225
244
def report_grind_command
@@ -241,6 +260,7 @@ def report_grind_command
241
260
build : test_time_record ,
242
261
limit : queue_config . max_test_duration ,
243
262
percentile : queue_config . max_test_duration_percentile ,
263
+ export_file : queue_config . export_timing_file
244
264
)
245
265
test_time_reporter . report
246
266
@@ -564,6 +584,38 @@ def parser
564
584
self . test_globs = test_globs
565
585
end
566
586
587
+ help = <<~EOS
588
+ Test ordering strategy: random, timing_based (default: random)
589
+ EOS
590
+ opts . separator ""
591
+ opts . on ( '--strategy STRATEGY' , help ) do |strategy |
592
+ queue_config . strategy = strategy . to_sym
593
+ end
594
+
595
+ help = <<~EOS
596
+ Path to JSON timing file for timing_based strategy
597
+ EOS
598
+ opts . separator ""
599
+ opts . on ( '--timing-file PATH' , help ) do |path |
600
+ queue_config . timing_file = path
601
+ end
602
+
603
+ help = <<~EOS
604
+ Fallback duration in ms for unknown tests (default: 100)
605
+ EOS
606
+ opts . separator ""
607
+ opts . on ( '--timing-fallback DURATION' , Float , help ) do |duration |
608
+ queue_config . timing_fallback_duration = duration
609
+ end
610
+
611
+ help = <<~EOS
612
+ Export test timing data to JSON file after run (use with report command)
613
+ EOS
614
+ opts . separator ""
615
+ opts . on ( '--export-timing-file PATH' , help ) do |path |
616
+ queue_config . export_timing_file = path
617
+ end
618
+
567
619
opts . separator ""
568
620
opts . separator " retry: Replays a previous run in the same order."
569
621
0 commit comments