diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/models/protected_branch_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/models/protected_branch_spec.rb')
-rw-r--r-- | spec/models/protected_branch_spec.rb | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index 3936e7127b8..54a90ca6049 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -171,8 +171,8 @@ RSpec.describe ProtectedBranch do let_it_be(:project) { create(:project, :repository) } let_it_be(:protected_branch) { create(:protected_branch, project: project, name: "“jawn”") } - let(:feature_flag) { true } - let(:dry_run) { true } + let(:use_new_cache_implementation) { true } + let(:rely_on_new_cache) { true } shared_examples_for 'hash based cache implementation' do it 'calls only hash based cache implementation' do @@ -182,19 +182,22 @@ RSpec.describe ProtectedBranch do expect(Rails.cache).not_to receive(:fetch) - described_class.protected?(project, 'missing-branch', dry_run: dry_run) + described_class.protected?(project, 'missing-branch') end end before do - stub_feature_flags(hash_based_cache_for_protected_branches: feature_flag) + stub_feature_flags(hash_based_cache_for_protected_branches: use_new_cache_implementation) + stub_feature_flags(rely_on_protected_branches_cache: rely_on_new_cache) allow(described_class).to receive(:matching).and_call_original # the original call works and warms the cache - described_class.protected?(project, protected_branch.name, dry_run: dry_run) + described_class.protected?(project, protected_branch.name) end - context 'Dry-run: true' do + context 'Dry-run: true (rely_on_protected_branches_cache is off, new hash-based is used)' do + let(:rely_on_new_cache) { false } + it 'recalculates a fresh value every time in order to check the cache is not returning stale data' do expect(described_class).to receive(:matching).with(protected_branch.name, protected_refs: anything).twice @@ -204,21 +207,21 @@ RSpec.describe ProtectedBranch do it_behaves_like 'hash based cache implementation' end - context 'Dry-run: false' do - let(:dry_run) { false } + context 'Dry-run: false (rely_on_protected_branches_cache is enabled, new hash-based cache is used)' do + let(:rely_on_new_cache) { true } it 'correctly invalidates a cache' do expect(described_class).to receive(:matching).with(protected_branch.name, protected_refs: anything).exactly(3).times.and_call_original create_params = { name: 'bar', merge_access_levels_attributes: [{ access_level: Gitlab::Access::DEVELOPER }] } branch = ProtectedBranches::CreateService.new(project, project.owner, create_params).execute - expect(described_class.protected?(project, protected_branch.name, dry_run: dry_run)).to eq(true) + expect(described_class.protected?(project, protected_branch.name)).to eq(true) ProtectedBranches::UpdateService.new(project, project.owner, name: 'ber').execute(branch) - expect(described_class.protected?(project, protected_branch.name, dry_run: dry_run)).to eq(true) + expect(described_class.protected?(project, protected_branch.name)).to eq(true) ProtectedBranches::DestroyService.new(project, project.owner).execute(branch) - expect(described_class.protected?(project, protected_branch.name, dry_run: dry_run)).to eq(true) + expect(described_class.protected?(project, protected_branch.name)).to eq(true) end it_behaves_like 'hash based cache implementation' @@ -229,7 +232,7 @@ RSpec.describe ProtectedBranch do project.touch - described_class.protected?(project, protected_branch.name, dry_run: dry_run) + described_class.protected?(project, protected_branch.name) end end @@ -240,19 +243,19 @@ RSpec.describe ProtectedBranch do another_project = create(:project) ProtectedBranches::CreateService.new(another_project, another_project.owner, name: 'bar').execute - described_class.protected?(project, protected_branch.name, dry_run: dry_run) + described_class.protected?(project, protected_branch.name) end end it 'correctly uses the cached version' do expect(described_class).not_to receive(:matching) - expect(described_class.protected?(project, protected_branch.name, dry_run: dry_run)).to eq(true) + expect(described_class.protected?(project, protected_branch.name)).to eq(true) end end context 'when feature flag hash_based_cache_for_protected_branches is off' do - let(:feature_flag) { false } + let(:use_new_cache_implementation) { false } it 'does not call hash based cache implementation' do expect(ProtectedBranches::CacheService).not_to receive(:new) |