From 37c65903f5d8aec294f78ac00a6692e556468790 Mon Sep 17 00:00:00 2001 From: Aiden Storey Date: Wed, 29 Apr 2026 14:52:45 -0400 Subject: [PATCH 1/2] Add test id normalizer to configuration --- ruby/lib/ci/queue/configuration.rb | 16 +++- .../configuration_test/normalizer_test.rb | 89 +++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 ruby/test/ci/queue/configuration_test/normalizer_test.rb diff --git a/ruby/lib/ci/queue/configuration.rb b/ruby/lib/ci/queue/configuration.rb index d097f507..6dfe3a86 100644 --- a/ruby/lib/ci/queue/configuration.rb +++ b/ruby/lib/ci/queue/configuration.rb @@ -172,7 +172,21 @@ def max_duration=(duration) end def flaky?(test) - @flaky_tests.include?(test.id) + lazy_normalized_flaky_tests.include?(normalize_test_id(test.id)) + end + + def normalize_test_id(id) + id + end + + def lazy_normalized_flaky_tests + @normalized_flaky_tests ||= @flaky_tests.to_set { |test_id| normalize_test_id(test_id) } + end + + def test_id_normalizer=(normalizer) + normalizer = normalizer.to_proc if Method === normalizer + define_singleton_method(:normalize_test_id, normalizer) + @normalized_flaky_tests = nil end def seed diff --git a/ruby/test/ci/queue/configuration_test/normalizer_test.rb b/ruby/test/ci/queue/configuration_test/normalizer_test.rb new file mode 100644 index 00000000..375fc265 --- /dev/null +++ b/ruby/test/ci/queue/configuration_test/normalizer_test.rb @@ -0,0 +1,89 @@ +module CI + module Queue + class ConfigurationTest < Minitest::Test + class NormalizerTest < Minitest::Test + module ExampleHelper + extend self + + def normalize(id) + id.sub(%r{^\./}, "") + end + + def strip(id) + id.strip + end + end + + def test_flaky_without_normalizer + config = Configuration.new(flaky_tests: Set["ATest#test_foo", "BTest#test_bar"]) + + test = Struct.new(:id).new("ATest#test_foo") + assert config.flaky?(test) + + test = Struct.new(:id).new("CTest#test_baz") + refute config.flaky?(test) + end + + def test_flaky_with_instance_method_normalizer + config = Configuration.new(flaky_tests: Set["./test/my_test.rb:ATest#test_foo", "./test/my_test.rb:BTest#test_bar"]) + config.test_id_normalizer = ExampleHelper.instance_method(:normalize) + + test = Struct.new(:id).new("test/my_test.rb:ATest#test_foo") + assert config.flaky?(test) + + test = Struct.new(:id).new("test/my_test.rb:CTest#test_baz") + refute config.flaky?(test) + end + + def test_flaky_with_method_normalizer + config = Configuration.new(flaky_tests: Set["./test/my_test.rb:ATest#test_foo", "./test/my_test.rb:BTest#test_bar"]) + config.test_id_normalizer = ExampleHelper.method(:normalize) + + test = Struct.new(:id).new("test/my_test.rb:ATest#test_foo") + assert config.flaky?(test) + + test = Struct.new(:id).new("test/my_test.rb:CTest#test_baz") + refute config.flaky?(test) + end + + def test_flakey_with_proc + config = Configuration.new(flaky_tests: Set["./test/my_test.rb:ATest#test_foo", "./test/my_test.rb:BTest#test_bar"]) + config.test_id_normalizer = proc { |id| id.sub(%r{^\./}, "") } + + test = Struct.new(:id).new("test/my_test.rb:ATest#test_foo") + assert config.flaky?(test) + + test = Struct.new(:id).new("test/my_test.rb:CTest#test_baz") + refute config.flaky?(test) + end + + def test_flaky_normalizer_applied_to_both_sides + config = Configuration.new(flaky_tests: Set[" ATest#test_foo ", "BTest#test_bar"]) + config.test_id_normalizer = ExampleHelper.instance_method(:strip) + + test = Struct.new(:id).new("ATest#test_foo") + assert config.flaky?(test) + + test = Struct.new(:id).new(" ATest#test_foo ") + assert config.flaky?(test) + end + + def test_flaky_normalizer_invalidates_cache + config = Configuration.new(flaky_tests: Set["./test/my_test.rb:ATest#test_foo"]) + test = Struct.new(:id).new("test/my_test.rb:ATest#test_foo") + + refute config.flaky?(test) + + config.test_id_normalizer = ExampleHelper.instance_method(:normalize) + + assert config.flaky?(test) + end + + def test_flaky_normalized_lookup_uses_set + config = Configuration.new(flaky_tests: Set["ATest#test_foo"]) + assert_kind_of Set, config.lazy_normalized_flaky_tests + end + end + end + end +end From 40f48c9e4c1d08619ff4148f9807599abb0bea66 Mon Sep 17 00:00:00 2001 From: Aiden Storey Date: Tue, 5 May 2026 12:04:41 -0400 Subject: [PATCH 2/2] Bump ci-queue to v0.95.0 --- ruby/Gemfile.lock | 2 +- ruby/lib/ci/queue/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index 2b33c3d7..cf773d72 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ci-queue (0.94.0) + ci-queue (0.95.0) logger GEM diff --git a/ruby/lib/ci/queue/version.rb b/ruby/lib/ci/queue/version.rb index 03874a73..0dee1b27 100644 --- a/ruby/lib/ci/queue/version.rb +++ b/ruby/lib/ci/queue/version.rb @@ -2,7 +2,7 @@ module CI module Queue - VERSION = '0.94.0' + VERSION = '0.95.0' DEV_SCRIPTS_ROOT = ::File.expand_path('../../../../../redis', __FILE__) RELEASE_SCRIPTS_ROOT = ::File.expand_path('../redis', __FILE__) end