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 ...@@ -7,13 +7,11 @@ module Gitlab
class_methods do class_methods do
def validator def validator
validator = Class.new(Node::Validator) @validator ||= Class.new(Node::Validator).tap do |validator|
if defined?(@validations) if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) } @validations.each { |rules| validator.class_eval(&rules) }
end end
end
validator
end end
private private
......
...@@ -23,6 +23,10 @@ describe Gitlab::Ci::Config::Node::Validatable do ...@@ -23,6 +23,10 @@ describe Gitlab::Ci::Config::Node::Validatable do
.to be Gitlab::Ci::Config::Node::Validator .to be Gitlab::Ci::Config::Node::Validator
end 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 context 'when validating node instance' do
let(:node_instance) { node.new } 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