Skip to content

Commit 99cbd1f

Browse files
committed
do not override file timings with partial timings
When a requeue is executed its timing is recorded. This triggers the whole-file-timings reconstruction that sums up examples to deduce the whole file's duration. So we might end up with a timing for a file that was not splitted at all!
1 parent 63285e1 commit 99cbd1f

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/rspecq/queue.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ def global_timings
302302
whole_file_timings = populate_splitted_file_timings(redis_timings)
303303
return redis_timings if whole_file_timings.empty?
304304

305-
redis_timings.merge!(whole_file_timings)
306-
redis_timings.sort_by { |_j, d| -d }.to_h
305+
# Make sure that redis_timings overrides whole_file_timings in case
306+
# there are any duplicates
307+
whole_file_timings.merge!(redis_timings)
308+
whole_file_timings.sort_by { |_j, d| -d }.to_h
307309
end
308310

309311
# ordered by execution time desc (slowest are in the head)

test/test_queue.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,17 @@ def test_push_jobs_returns_jobs_size
3030

3131
assert_equal 2, queue.push_jobs(["job1", "job2"])
3232
end
33+
34+
def test_timings_reconstruction
35+
queue = RSpecQ::Queue.new(rand_id, rand_id, REDIS_OPTS)
36+
37+
queue.record_build_timing("foo", 42.0)
38+
queue.record_build_timing("foo[1]", 1.0)
39+
40+
queue.update_global_timings
41+
42+
global_timings = queue.global_timings
43+
44+
assert_equal 42.0, global_timings["foo"], "File timing should not be overriden"
45+
end
3346
end

0 commit comments

Comments
 (0)