Skip to content

Commit 78f4d58

Browse files
committed
populate_splitted_file_timings
1 parent b029805 commit 78f4d58

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

lib/rspecq/queue.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,17 @@ def become_master
280280

281281
# ordered by execution time desc (slowest are in the head)
282282
def global_timings
283-
@redis.zrevrange(key_timings, 0, -1, withscores: true).to_h
283+
redis_timings = @redis.zrevrange(key_timings, 0, -1, withscores: true).to_h
284+
285+
# Populate timings for whole files that were split into individual
286+
# examples, by summing up the timings of their individual parts.
287+
#
288+
# We need that so that the scheduler will be able to mark them for splitting again
289+
whole_file_timings = populate_splitted_file_timings(redis_timings)
290+
return redis_timings if whole_file_timings.empty?
291+
292+
redis_timings.merge!(whole_file_timings)
293+
redis_timings.sort_by { |_j, d| -d }.to_h
284294
end
285295

286296
# ordered by execution time desc (slowest are in the head)
@@ -530,5 +540,20 @@ def key(*keys)
530540
def current_time
531541
@redis.time[0]
532542
end
543+
544+
# Given a set splitted file timing entries, we reconstruct the file's
545+
# timings by summing up the timings of its individual parts.
546+
def populate_splitted_file_timings(timings)
547+
whole_file_timings = Hash.new(0)
548+
549+
timings.each do |file, duration|
550+
next if !file.include?("[")
551+
552+
base_file = file.split("[").first
553+
whole_file_timings[base_file] += duration
554+
end
555+
556+
whole_file_timings
557+
end
533558
end
534559
end

0 commit comments

Comments
 (0)