Skip to content

Commit 7ac3885

Browse files
ssteele110claude
andcommitted
Refactor: extract execute_master_setup to remove duplication
Extract shared master setup logic (reorder tests, store chunk metadata, push to queue) into execute_master_setup method. Used by both initial master setup in populate() and takeover in run_master_setup(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7597524 commit 7ac3885

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

‎ruby/lib/ci/queue/redis/worker.rb‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,9 @@ def populate(tests, random: Random.new)
3434
# All workers need an index of tests to resolve IDs
3535
@index = tests.map { |t| [t.id, t] }.to_h
3636
@total = tests.size
37+
@random = random
3738

38-
if acquire_master_role?
39-
with_master_setup_heartbeat do
40-
executables = reorder_tests(tests, random: random)
41-
42-
chunks = executables.select { |e| e.is_a?(CI::Queue::TestChunk) }
43-
individual_tests = executables.reject { |e| e.is_a?(CI::Queue::TestChunk) }
44-
45-
store_chunk_metadata(chunks) if chunks.any?
46-
47-
all_ids = chunks.map(&:id) + individual_tests.map(&:id)
48-
push(all_ids)
49-
end
50-
end
39+
execute_master_setup(tests) if acquire_master_role?
5140

5241
register_worker_presence
5342

@@ -577,13 +566,14 @@ def register_worker_presence
577566
def run_master_setup
578567
return unless @master && @index
579568

580-
# Reconstruct tests array from index
581-
tests = @index.values
569+
execute_master_setup(@index.values)
570+
end
582571

572+
# Shared logic for master setup - reorders tests, stores chunk metadata, and pushes to queue.
573+
# Used by both initial master setup (populate) and takeover (run_master_setup).
574+
def execute_master_setup(tests)
583575
with_master_setup_heartbeat do
584-
# Use the same seed for deterministic ordering
585-
random = Random.new(Digest::MD5.hexdigest(config.seed).to_i(16))
586-
executables = reorder_tests(tests, random: random)
576+
executables = reorder_tests(tests, random: @random)
587577

588578
chunks = executables.select { |e| e.is_a?(CI::Queue::TestChunk) }
589579
individual_tests = executables.reject { |e| e.is_a?(CI::Queue::TestChunk) }

0 commit comments

Comments
 (0)