diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-07 15:52:05 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-07 15:52:05 +0000 |
commit | 984dc66b0766db14d010b89fbf652fd6fe3ea8db (patch) | |
tree | dbc653a91300d614546e73986c2f0e346f3f0909 /spec | |
parent | 14184b159db309ff0d1b5ec5926bfb2f33dbbc70 (diff) | |
download | gitlab-ce-984dc66b0766db14d010b89fbf652fd6fe3ea8db.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/group_spec.rb | 71 | ||||
-rw-r--r-- | spec/services/ci/runners/assign_runner_service_spec.rb | 4 |
2 files changed, 71 insertions, 4 deletions
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 297b11bd72a..98fad544abd 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -2191,7 +2191,7 @@ RSpec.describe Group do let(:group) { create(:group) } - subject { group.first_auto_devops_config } + subject(:fetch_config) { group.first_auto_devops_config } where(:instance_value, :group_value, :config) do # Instance level enabled @@ -2216,6 +2216,8 @@ RSpec.describe Group do end context 'with parent groups' do + let(:parent) { create(:group) } + where(:instance_value, :parent_value, :group_value, :config) do # Instance level enabled true | nil | nil | { status: true, scope: :instance } @@ -2245,17 +2247,82 @@ RSpec.describe Group do end with_them do + def define_cache_expectations(cache_key) + if group_value.nil? + expect(Rails.cache).to receive(:fetch).with(start_with(cache_key), expires_in: 1.day) + else + expect(Rails.cache).not_to receive(:fetch).with(start_with(cache_key), expires_in: 1.day) + end + end + before do stub_application_setting(auto_devops_enabled: instance_value) - parent = create(:group, auto_devops_enabled: parent_value) group.update!( auto_devops_enabled: group_value, parent: parent ) + parent.update!(auto_devops_enabled: parent_value) + + group.reload # Reload so we get the populated traversal IDs end it { is_expected.to eq(config) } + + it 'caches the parent config when group auto_devops_enabled is nil' do + cache_key = "namespaces:{#{group.traversal_ids.first}}:first_auto_devops_config:#{group.id}" + define_cache_expectations(cache_key) + + fetch_config + end + + context 'when traversal ID feature flags are disabled' do + before do + stub_feature_flags(sync_traversal_ids: false) + end + + it 'caches the parent config when group auto_devops_enabled is nil' do + cache_key = "namespaces:{first_auto_devops_config}:#{group.id}" + define_cache_expectations(cache_key) + + fetch_config + end + end + end + + context 'cache expiration' do + before do + group.update!(parent: parent) + + reload_models(parent) + end + + it 'clears both self and descendant cache when the parent value is updated' do + expect(Rails.cache).to receive(:delete_multi) + .with( + match_array([ + start_with("namespaces:{#{parent.traversal_ids.first}}:first_auto_devops_config:#{parent.id}"), + start_with("namespaces:{#{parent.traversal_ids.first}}:first_auto_devops_config:#{group.id}") + ]) + ) + + parent.update!(auto_devops_enabled: true) + end + + it 'only clears self cache when there are no dependents' do + expect(Rails.cache).to receive(:delete_multi) + .with([start_with("namespaces:{#{group.traversal_ids.first}}:first_auto_devops_config:#{group.id}")]) + + group.update!(auto_devops_enabled: true) + end + + it 'does not clear cache when the feature is disabled' do + stub_feature_flags(namespaces_cache_first_auto_devops_config: false) + + expect(Rails.cache).not_to receive(:delete_multi) + + parent.update!(auto_devops_enabled: true) + end end end end diff --git a/spec/services/ci/runners/assign_runner_service_spec.rb b/spec/services/ci/runners/assign_runner_service_spec.rb index 2997dfd7027..00b176bb759 100644 --- a/spec/services/ci/runners/assign_runner_service_spec.rb +++ b/spec/services/ci/runners/assign_runner_service_spec.rb @@ -5,8 +5,8 @@ require 'spec_helper' RSpec.describe ::Ci::Runners::AssignRunnerService, '#execute' do subject { described_class.new(runner, project, user).execute } - let_it_be(:runner) { build(:ci_runner) } - let_it_be(:project) { build(:project) } + let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) } + let_it_be(:project) { create(:project) } context 'without user' do let(:user) { nil } |