Merge branch 'fix/improve-ci-node-validatable-to-prevent-memory-leak' into 'master'
Memoize CI config node validator to prevent leaks ## What does this MR do? This MR memoizes CI configuration node validator, to prevent possible memory leak described in #20698. ## Why was this MR needed? See #20698 ## What are the relevant issue numbers? Closes #20698 ## Does this MR meet the acceptance criteria? - [ ] ~~[CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added~~ - [ ] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - [ ] ~~API support added~~ - Tests - [x] Added for this feature/bug - [x] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5733
This commit is contained in:
commit
b8130d42c2
2 changed files with 8 additions and 6 deletions
|
@ -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
|
||||||
.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 }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue