Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle key errors gracefully in a static queue #272

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading