Skip to content

Commit

Permalink
Handle key errors gracefully in a static queue
Browse files Browse the repository at this point in the history
  • Loading branch information
zarifmahfuz committed Apr 18, 2024
1 parent 1937530 commit 1d8fa18
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ruby/lib/ci/queue/static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ def populated?
end

def to_a
@queue.map { |i| index.fetch(i) }
@queue.map do |i|
index.fetch(i)
rescue KeyError
puts "Test not found: #{i}"
nil
end.compact
end

def size
Expand All @@ -88,7 +93,11 @@ def running

def poll
while !@shutdown && config.circuit_breakers.none?(&:open?) && !max_test_failed? && @reserved_test = @queue.shift
yield index.fetch(@reserved_test)
begin
yield index.fetch(@reserved_test)
rescue KeyError
puts "Test not found: #{@reserved_test}"
end
end
@reserved_test = nil
end
Expand Down
30 changes: 30 additions & 0 deletions ruby/test/ci/queue/static_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ def test_expired
refute queue.expired?
end

def test_poll_skips_missing_test
queue = CI::Queue::Static.new((TEST_LIST + [TestCase.new('ATest#i_do_not_exist')]).map(&:id), config)
populate(queue)

expected_output = <<~OUTPUT
Test not found: ATest#i_do_not_exist
OUTPUT

out, _ = capture_io do
assert_equal shuffled_test_list, poll(queue)
end

assert_equal expected_output, out
end

def test_to_a_skips_missing_test
queue = CI::Queue::Static.new((TEST_LIST + [TestCase.new('ATest#i_do_not_exist')]).map(&:id), config)
populate(queue)

expected_output = <<~OUTPUT
Test not found: ATest#i_do_not_exist
OUTPUT

out, _ = capture_io do
assert_equal shuffled_test_list, queue.to_a
end

assert_equal expected_output, out
end

private

def build_queue
Expand Down

0 comments on commit 1d8fa18

Please sign in to comment.