Commit f3f1b010 authored by Sean McGivern's avatar Sean McGivern

Use public project in UpdateAllMirrorsWorker specs

This public project allows us to test the next change effectively.
parent 4a09d7b3
...@@ -126,7 +126,7 @@ describe UpdateAllMirrorsWorker do ...@@ -126,7 +126,7 @@ describe UpdateAllMirrorsWorker do
projects.each { |project| expect_import_status(project, 'none') } projects.each { |project| expect_import_status(project, 'none') }
end end
context 'unlicensed' do context 'when the instance is unlicensed' do
it 'does not schedule when project does not have repository mirrors available' do it 'does not schedule when project does not have repository mirrors available' do
project = create(:project, :mirror) project = create(:project, :mirror)
...@@ -138,42 +138,47 @@ describe UpdateAllMirrorsWorker do ...@@ -138,42 +138,47 @@ describe UpdateAllMirrorsWorker do
end end
end end
context 'licensed' do context 'on GitLab.com' do
def scheduled_mirror(at:, licensed:) def scheduled_mirror(at:, licensed:, public: false, subgroup: nil)
namespace = create(:group, :public) group_args = [:group, :public, subgroup && :nested].compact
namespace = create(*group_args)
project = create(:project, :public, :mirror, namespace: namespace) project = create(:project, :public, :mirror, namespace: namespace)
create(:gitlab_subscription, (licensed ? :bronze : :free), namespace: namespace) create(:gitlab_subscription, (licensed ? :bronze : :free), namespace: namespace.root_ancestor)
project.import_state.update!(next_execution_timestamp: at) project.import_state.update!(next_execution_timestamp: at)
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) unless public
project project
end end
before do before do
stub_licensed_features(repository_mirrors: true)
stub_application_setting(check_namespace_plan: true) stub_application_setting(check_namespace_plan: true)
allow(Gitlab).to receive_messages(com?: true)
stub_const('License::ANY_PLAN_FEATURES', [])
end end
let!(:unlicensed_project1) { scheduled_mirror(at: 8.weeks.ago, licensed: false) } let_it_be(:unlicensed_project1) { scheduled_mirror(at: 8.weeks.ago, licensed: false) }
let!(:unlicensed_project2) { scheduled_mirror(at: 7.weeks.ago, licensed: false) } let_it_be(:unlicensed_project2) { scheduled_mirror(at: 7.weeks.ago, licensed: false) }
let!(:licensed_project1) { scheduled_mirror(at: 6.weeks.ago, licensed: true) } let_it_be(:licensed_project1) { scheduled_mirror(at: 6.weeks.ago, licensed: true, subgroup: true) }
let!(:unlicensed_project3) { scheduled_mirror(at: 5.weeks.ago, licensed: false) } let_it_be(:unlicensed_project3) { scheduled_mirror(at: 5.weeks.ago, licensed: false) }
let!(:licensed_project2) { scheduled_mirror(at: 4.weeks.ago, licensed: true) } let_it_be(:licensed_project2) { scheduled_mirror(at: 4.weeks.ago, licensed: true) }
let!(:unlicensed_project4) { scheduled_mirror(at: 3.weeks.ago, licensed: false) } let_it_be(:unlicensed_project4) { scheduled_mirror(at: 3.weeks.ago, licensed: false) }
let!(:licensed_project3) { scheduled_mirror(at: 1.week.ago, licensed: true) } let_it_be(:public_project) { scheduled_mirror(at: 1.week.ago, licensed: false, public: true) }
let(:unlicensed_projects) { [unlicensed_project1, unlicensed_project2, unlicensed_project3, unlicensed_project4] } let(:unlicensed_projects) { [unlicensed_project1, unlicensed_project2, unlicensed_project3, unlicensed_project4] }
context 'during the free period for pull mirroring' do
before do
stub_const('License::ANY_PLAN_FEATURES', [])
end
context 'when capacity is in excess' do context 'when capacity is in excess' do
it "schedules all available mirrors" do it "schedules all available mirrors" do
schedule_mirrors!(capacity: 4) schedule_mirrors!(capacity: 4)
expect_import_scheduled(licensed_project1, licensed_project2, licensed_project3) aggregate_failures do
expect_import_scheduled(licensed_project1, licensed_project2, public_project)
expect_import_not_scheduled(*unlicensed_projects) expect_import_not_scheduled(*unlicensed_projects)
end end
end
it 'requests as many batches as necessary' do it 'requests as many batches as necessary' do
# The first batch will only contain 3 licensed mirrors, but since we have # The first batch will only contain 3 licensed mirrors, but since we have
...@@ -188,7 +193,7 @@ describe UpdateAllMirrorsWorker do ...@@ -188,7 +193,7 @@ describe UpdateAllMirrorsWorker do
schedule_mirrors!(capacity: 4) schedule_mirrors!(capacity: 4)
expect_import_scheduled(licensed_project2, licensed_project3) expect_import_scheduled(licensed_project2, public_project)
expect_import_not_scheduled(licensed_project1) expect_import_not_scheduled(licensed_project1)
expect_import_not_scheduled(*unlicensed_projects) expect_import_not_scheduled(*unlicensed_projects)
end end
...@@ -198,7 +203,7 @@ describe UpdateAllMirrorsWorker do ...@@ -198,7 +203,7 @@ describe UpdateAllMirrorsWorker do
it "schedules all available mirrors" do it "schedules all available mirrors" do
schedule_mirrors!(capacity: 3) schedule_mirrors!(capacity: 3)
expect_import_scheduled(licensed_project1, licensed_project2, licensed_project3) expect_import_scheduled(licensed_project1, licensed_project2, public_project)
expect_import_not_scheduled(*unlicensed_projects) expect_import_not_scheduled(*unlicensed_projects)
end end
...@@ -216,7 +221,7 @@ describe UpdateAllMirrorsWorker do ...@@ -216,7 +221,7 @@ describe UpdateAllMirrorsWorker do
schedule_mirrors!(capacity: 2) schedule_mirrors!(capacity: 2)
expect_import_scheduled(licensed_project1, licensed_project2) expect_import_scheduled(licensed_project1, licensed_project2)
expect_import_not_scheduled(*unlicensed_projects, licensed_project3) expect_import_not_scheduled(*unlicensed_projects, public_project)
end end
it 'requests as many batches as necessary' do it 'requests as many batches as necessary' do
...@@ -233,7 +238,7 @@ describe UpdateAllMirrorsWorker do ...@@ -233,7 +238,7 @@ describe UpdateAllMirrorsWorker do
schedule_mirrors!(capacity: 1) schedule_mirrors!(capacity: 1)
expect_import_scheduled(licensed_project1) expect_import_scheduled(licensed_project1)
expect_import_not_scheduled(*unlicensed_projects, licensed_project2, licensed_project3) expect_import_not_scheduled(*unlicensed_projects, licensed_project2, public_project)
end end
it 'requests as many batches as necessary' do it 'requests as many batches as necessary' do
...@@ -246,4 +251,5 @@ describe UpdateAllMirrorsWorker do ...@@ -246,4 +251,5 @@ describe UpdateAllMirrorsWorker do
end end
end end
end end
end
end end
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