diff --git a/ruby/lib/ci/queue/static.rb b/ruby/lib/ci/queue/static.rb index 6b12fc8e..d353b1d3 100644 --- a/ruby/lib/ci/queue/static.rb +++ b/ruby/lib/ci/queue/static.rb @@ -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 @@ -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 diff --git a/ruby/test/ci/queue/static_test.rb b/ruby/test/ci/queue/static_test.rb index 9c11fc41..70305ce0 100644 --- a/ruby/test/ci/queue/static_test.rb +++ b/ruby/test/ci/queue/static_test.rb @@ -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