Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
ci-queue (0.94.0)
ci-queue (0.95.0)
logger

GEM
Expand Down
16 changes: 15 additions & 1 deletion ruby/lib/ci/queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
bitwise-aiden marked this conversation as resolved.
end

def seed
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/ci/queue/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions ruby/test/ci/queue/configuration_test/normalizer_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading