Commit 57451f52 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Memoize CI config node validator to prevent leaks

parent 551ffc0a
......@@ -7,13 +7,11 @@ module Gitlab
class_methods do
def validator
validator = Class.new(Node::Validator)
if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) }
@validator ||= Class.new(Node::Validator).tap do |validator|
if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) }
end
end
validator
end
private
......
......@@ -23,6 +23,10 @@ describe Gitlab::Ci::Config::Node::Validatable do
.to be Gitlab::Ci::Config::Node::Validator
end
it 'returns only one validator to mitigate leaks' do
expect { node.validator }.not_to change { node.validator }
end
context 'when validating node instance' do
let(:node_instance) { node.new }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment