From 0d70dec86ec09d27589ce89a35089612a4f07f52 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 26 Aug 2013 18:08:56 +0400 Subject: [PATCH] #276: updated specs for BuildListsPublishTaskManager --- app/models/repository.rb | 2 +- .../build_lists_publish_task_manager.rb | 22 ++- .../build_lists_publish_task_manager_spec.rb | 159 +++++------------- 3 files changed, 60 insertions(+), 123 deletions(-) diff --git a/app/models/repository.rb b/app/models/repository.rb index d89c22035..ae2433142 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -26,7 +26,7 @@ class Repository < ActiveRecord::Base attr_accessible :name, :description, :publish_without_qa attr_readonly :name, :platform_id - def regenerate(build_for_platform_id) + def regenerate(build_for_platform_id = nil) build_for_platform = Platform.main.find build_for_platform_id if platform.personal? status = repository_statuses.find_or_create_by_platform_id(build_for_platform.try(:id) || platform_id) status.regenerate diff --git a/lib/abf_worker/build_lists_publish_task_manager.rb b/lib/abf_worker/build_lists_publish_task_manager.rb index 3a78185d7..28fc4611b 100644 --- a/lib/abf_worker/build_lists_publish_task_manager.rb +++ b/lib/abf_worker/build_lists_publish_task_manager.rb @@ -146,9 +146,11 @@ module AbfWorker private def create_tasks_for_resign_repositories - repository_statuses = RepositoryStatus.platform_ready. - for_resign.includes(:repository => :platform) - repository_statuses.each do |repository_status| + RepositoryStatus.platform_ready + .for_resign + .includes(:repository => :platform) + .readonly(false) + .each do |repository_status| r = repository_status.repository # Checks mirror sync status next if r.repo_lock_file_exists? @@ -249,7 +251,7 @@ module AbfWorker # Checks mirror sync status return false if save_to_repository.repo_lock_file_exists? || !save_to_repository.platform.ready? - repository_status = save_to_repository.find_or_create_by_platform_id(build_for_platform_id) + repository_status = save_to_repository.repository_statuses.find_or_create_by_platform_id(build_for_platform_id) return false unless repository_status.publish save_to_platform = save_to_repository.platform @@ -318,7 +320,7 @@ module AbfWorker end def create_tasks_for_regenerate_metadata_for_software_center - Platfor.main.waiting_for_regeneration.each do |platform| + Platform.main.waiting_for_regeneration.each do |platform| repos = platform.repositories statuses = RepositoryStatus.where(:platform_id => platform.id) next if repos.find{ |r| r.repo_lock_file_exists? } @@ -358,14 +360,16 @@ module AbfWorker end def create_tasks_for_repository_regenerate_metadata - repository_statuses = RepositoryStatus.platform_ready. - for_regeneration.includes(:repository => :platform) - repository_statuses.each do |repository_status| + RepositoryStatus.platform_ready + .for_regeneration + .includes(:repository => :platform) + .readonly(false) + .each do |repository_status| rep = repository_status.repository # Checks mirror sync status next if rep.repo_lock_file_exists? - build_for_platform = repository_statuses.platform + build_for_platform = repository_status.platform cmd_params = { 'RELEASED' => rep.platform.released, 'REPOSITORY_NAME' => rep.name, diff --git a/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb b/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb index 8ed43984c..2cd0c17e8 100644 --- a/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb +++ b/spec/lib/abf-worker/build_lists_publish_task_manager_spec.rb @@ -7,7 +7,7 @@ describe AbfWorker::BuildListsPublishTaskManager do end before do - init_test_root + stub_redis stub_symlink_methods FactoryGirl.create(:build_list) end @@ -16,25 +16,19 @@ describe AbfWorker::BuildListsPublishTaskManager do let(:build_list) { FactoryGirl.create(:build_list) } context 'when no items for publishing' do - before do - stub_redis - subject.new.run - end + before { subject.new.run } - %w(RESIGN_REPOSITORIES - PROJECTS_FOR_CLEANUP + %w(PROJECTS_FOR_CLEANUP LOCKED_PROJECTS_FOR_CLEANUP - LOCKED_REPOSITORIES - LOCKED_REP_AND_PLATFORMS LOCKED_BUILD_LISTS).each do |kind| - it "ensure that no '#{kind.downcase.gsub('_', ' ')}'" do + it "ensures that no '#{kind.downcase.gsub('_', ' ')}'" do @redis_instance.lrange(subject.const_get(kind), 0, -1).should be_empty end end %w(publish_worker_default publish_worker).each do |kind| - it "ensure that no tasks in '#{kind}' queue" do + it "ensures that no tasks in '#{kind}' queue" do @redis_instance.lrange(kind, 0, -1).should be_empty end end @@ -43,33 +37,28 @@ describe AbfWorker::BuildListsPublishTaskManager do context 'when one build_list for publishing' do before do - stub_redis build_list.update_column(:status, BuildList::BUILD_PUBLISH) 2.times{ subject.new.run } end - %w(RESIGN_REPOSITORIES - PROJECTS_FOR_CLEANUP - LOCKED_PROJECTS_FOR_CLEANUP - LOCKED_REPOSITORIES).each do |kind| - + %w(PROJECTS_FOR_CLEANUP LOCKED_PROJECTS_FOR_CLEANUP).each do |kind| it "ensure that no '#{kind.downcase.gsub('_', ' ')}'" do @redis_instance.lrange(subject.const_get(kind), 0, -1).should be_empty end end - it "ensure that 'locked rep and platforms' has only one item" do - queue = @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1) - queue.should have(1).item - queue.should include("#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}") + it "ensures that repository_status has status publish" do + build_list.save_to_repository.repository_statuses. + find_by_platform_id(build_list.build_for_platform_id).publish?. + should be_true end - it "ensure that 'locked build lists' has only one item" do + it "ensures that 'locked build lists' has only one item" do queue = @redis_instance.lrange(subject::LOCKED_BUILD_LISTS, 0, -1) queue.should have(1).item queue.should include(build_list.id.to_s) end - it "ensure that new task for publishing has been created" do + it "ensures that new task for publishing has been created" do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item end @@ -83,35 +72,28 @@ describe AbfWorker::BuildListsPublishTaskManager do :build_for_platform => build_list.build_for_platform ) } before do - stub_redis build_list.update_column(:status, BuildList::BUILD_PUBLISH) build_list2.update_column(:status, BuildList::BUILD_PUBLISH) 2.times{ subject.new.run } end - %w(RESIGN_REPOSITORIES - PROJECTS_FOR_CLEANUP - LOCKED_PROJECTS_FOR_CLEANUP - LOCKED_REPOSITORIES).each do |kind| - - it "ensure that no '#{kind.downcase.gsub('_', ' ')}'" do + %w(PROJECTS_FOR_CLEANUP LOCKED_PROJECTS_FOR_CLEANUP).each do |kind| + it "ensures that no '#{kind.downcase.gsub('_', ' ')}'" do @redis_instance.lrange(subject.const_get(kind), 0, -1).should be_empty end end - it "ensure that 'locked rep and platforms' has only one item" do - queue = @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1) - queue.should have(1).item - queue.should include("#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}") + it "ensures that only one repository_status has status publish" do + RepositoryStatus.where(:status => RepositoryStatus::PUBLISH).should have(1).item end - it "ensure that 'locked build lists' has 2 items" do + it "ensures that 'locked build lists' has 2 items" do queue = @redis_instance.lrange(subject::LOCKED_BUILD_LISTS, 0, -1) queue.should have(2).item queue.should include(build_list.id.to_s, build_list2.id.to_s) end - it "ensure that new task for publishing has been created" do + it "ensures that new task for publishing has been created" do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item end @@ -119,7 +101,6 @@ describe AbfWorker::BuildListsPublishTaskManager do context 'creates not more than 4 tasks for publishing' do before do - stub_redis build_list.update_column(:status, BuildList::BUILD_PUBLISH) 4.times { bl = FactoryGirl.create(:build_list, :new_core => true) @@ -128,15 +109,15 @@ describe AbfWorker::BuildListsPublishTaskManager do 2.times{ subject.new.run } end - it "ensure that 'locked rep and platforms' has 4 items" do - @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1).should have(4).items + it "ensures that 4 repository_statuses have status publish" do + RepositoryStatus.where(:status => RepositoryStatus::PUBLISH).should have(4).items end - it "ensure that 'locked build lists' has 4 items" do + it "ensures that 'locked build lists' has 4 items" do @redis_instance.lrange(subject::LOCKED_BUILD_LISTS, 0, -1).should have(4).items end - it "ensure that new tasks for publishing has been created" do + it "ensures that new tasks for publishing has been created" do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(4).items end @@ -144,36 +125,29 @@ describe AbfWorker::BuildListsPublishTaskManager do context 'creates task for removing project from repository' do before do - stub_redis build_list.update_column(:status, BuildList::BUILD_PUBLISHED) FactoryGirl.create(:build_list_package, :build_list => build_list) ProjectToRepository.where(:project_id => build_list.project_id, :repository_id => build_list.save_to_repository_id).destroy_all 2.times{ subject.new.run } end - %w(RESIGN_REPOSITORIES - PROJECTS_FOR_CLEANUP - LOCKED_REPOSITORIES - LOCKED_BUILD_LISTS).each do |kind| - - it "ensure that no '#{kind.downcase.gsub('_', ' ')}'" do + %w(PROJECTS_FOR_CLEANUP LOCKED_BUILD_LISTS).each do |kind| + it "ensures that no '#{kind.downcase.gsub('_', ' ')}'" do @redis_instance.lrange(subject.const_get(kind), 0, -1).should be_empty end end - it "ensure that 'locked rep and platforms' has only one item" do - queue = @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1) - queue.should have(1).item - queue.should include("#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}") + it "ensures that only one repository_status has status publish" do + RepositoryStatus.where(:status => RepositoryStatus::PUBLISH).should have(1).item end - it "ensure that 'locked projects for cleanup' has only one item" do + it "ensures that 'locked projects for cleanup' has only one item" do queue = @redis_instance.lrange(subject::LOCKED_PROJECTS_FOR_CLEANUP, 0, -1) queue.should have(1).item queue.should include("#{build_list.project_id}-#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}") end - it "ensure that new task for publishing has been created" do + it "ensures that new task for publishing has been created" do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item end @@ -193,7 +167,6 @@ describe AbfWorker::BuildListsPublishTaskManager do :build_for_platform => build_list.build_for_platform ) } before do - stub_redis build_list.update_column(:status, BuildList::BUILD_PUBLISH) build_list2.update_column(:status, BuildList::BUILD_PUBLISHED) build_list3.update_column(:status, BuildList::BUILD_PUBLISHED) @@ -201,32 +174,25 @@ describe AbfWorker::BuildListsPublishTaskManager do 2.times{ subject.new.run } end - %w(RESIGN_REPOSITORIES - PROJECTS_FOR_CLEANUP - LOCKED_REPOSITORIES).each do |kind| - - it "ensure that no '#{kind.downcase.gsub('_', ' ')}'" do - @redis_instance.lrange(subject.const_get(kind), 0, -1).should be_empty - end + it "ensures that no 'projects for cleanup'" do + @redis_instance.lrange(subject::PROJECTS_FOR_CLEANUP, 0, -1).should be_empty end - it "ensure that 'locked rep and platforms' has only one item" do - queue = @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1) - queue.should have(1).item - queue.should include("#{build_list.save_to_repository_id}-#{build_list.build_for_platform_id}") + it "ensures that only one repository_status has status publish" do + RepositoryStatus.where(:status => RepositoryStatus::PUBLISH).should have(1).item end - it "ensure that 'locked projects for cleanup' has only one item" do + it "ensures that 'locked projects for cleanup' has only one item" do queue = @redis_instance.lrange(subject::LOCKED_PROJECTS_FOR_CLEANUP, 0, -1) queue.should have(1).item queue.should include("#{build_list3.project_id}-#{build_list3.save_to_repository_id}-#{build_list3.build_for_platform_id}") end - it "ensure that new task for publishing has been created" do + it "ensures that new task for publishing has been created" do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item end - it "ensure that 'locked build lists' has only one item" do + it "ensures that 'locked build lists' has only one item" do queue = @redis_instance.lrange(subject::LOCKED_BUILD_LISTS, 0, -1) queue.should have(1).item queue.should include(build_list.id.to_s) @@ -235,27 +201,19 @@ describe AbfWorker::BuildListsPublishTaskManager do context 'resign packages in repository' do before do - stub_redis build_list.update_column(:status, BuildList::BUILD_PUBLISH) FactoryGirl.create(:key_pair, :repository => build_list.save_to_repository) 2.times{ subject.new.run } end - %w(RESIGN_REPOSITORIES - PROJECTS_FOR_CLEANUP - LOCKED_PROJECTS_FOR_CLEANUP - LOCKED_REP_AND_PLATFORMS - LOCKED_BUILD_LISTS).each do |kind| - + %w(PROJECTS_FOR_CLEANUP LOCKED_PROJECTS_FOR_CLEANUP LOCKED_BUILD_LISTS).each do |kind| it "ensure that no '#{kind.downcase.gsub('_', ' ')}'" do @redis_instance.lrange(subject.const_get(kind), 0, -1).should be_empty end end - it "ensure that 'locked repositories' has only one item" do - queue = @redis_instance.lrange(subject::LOCKED_REPOSITORIES, 0, -1) - queue.should have(1).item - queue.should include(build_list.save_to_repository_id.to_s) + it "ensures that only one repository_status has status resign" do + RepositoryStatus.where(:status => RepositoryStatus::RESIGN).should have(1).item end it "ensure that new task for resign has been created" do @@ -265,29 +223,18 @@ describe AbfWorker::BuildListsPublishTaskManager do end context 'regenerate metadata' do - before do - stub_redis - end - context 'for repository of main platform' do let(:repository) { FactoryGirl.create(:repository) } before do - subject.repository_regenerate_metadata repository, repository.platform + repository.regenerate subject.new.run end - it "ensure that 'locked rep and platforms' has only one item" do - queue = @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1) - queue.should have(1).item - queue.should include("#{repository.id}-#{repository.platform.id}") + it "ensures that only one repository_status has status regenerating" do + RepositoryStatus.where(:status => RepositoryStatus::REGENERATING).should have(1).item end - it "ensure that 'regenerate metadata' queue without items" do - queue = @redis_instance.lrange(subject::REGENERATE_METADATA, 0, -1) - queue.should be_empty - end - - it 'ensure that new task has been created' do + it 'ensures that new task has been created' do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item end end @@ -296,33 +243,19 @@ describe AbfWorker::BuildListsPublishTaskManager do let(:main_platform) { FactoryGirl.create(:platform) } let(:repository) { FactoryGirl.create(:personal_repository) } before do - subject.repository_regenerate_metadata repository, main_platform + repository.regenerate main_platform.id subject.new.run end - it "ensure that 'locked rep and platforms' has only one item" do - @redis_instance.lrange(subject::LOCKED_REP_AND_PLATFORMS, 0, -1) - .should == ["#{repository.id}-#{main_platform.id}"] + it "ensures that only one repository_status has status regenerating" do + RepositoryStatus.where(:status => RepositoryStatus::REGENERATING).should have(1).item end - it "ensure that 'regenerate metadata' queue without items" do - @redis_instance.lrange(subject::REGENERATE_METADATA, 0, -1).should be_empty - end - - it 'ensure that new task has been created' do + it 'ensures that new task has been created' do @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item end end - it 'ensure that two tasks for regenerate one repository will not be created' do - repository = FactoryGirl.create(:repository) - 2.times do - subject.repository_regenerate_metadata repository, repository.platform - subject.new.run - end - @redis_instance.lrange('queue:publish_worker_default', 0, -1).should have(1).item - end - end after(:all) do