Skip to content

Commit

Permalink
[api][ci] turn consistency check into a job class
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Dec 4, 2015
1 parent ca0cfed commit 1771853
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'api_exception'
require 'xmlhash'

module AdminHelper
def consistency_check(fix = nil)
class InconsistentData < APIException; end

class ConsistencyCheckJob < ActiveJob::Base
def fix
perform(true)
end

def perform(fix = nil)
User.current ||= User.get_default_admin
errors = ""
errors = project_existens_consistency_check(fix)
Expand All @@ -11,9 +17,9 @@ def consistency_check(fix = nil)
errors << project_meta_check(prj, fix)
end
unless errors.blank?
Rails.logger.warn("Detected problems during consistency check")
Rails.logger.warn(errors)
raise APIException.new(errors)
Rails.logger.error("Detected problems during consistency check")
Rails.logger.error(errors)
raise InconsistentData.new(errors)
end
nil
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/config/clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ module Clockwork

# check for new breakages between api and backend due to dull code
every(1.week, 'consistency check') do
delay.consistency_check
ConsistencyCheckJob.new.delay.perform
end
end
5 changes: 3 additions & 2 deletions src/api/test/functional/aaa_pre_consistency_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + "/..") + "/test_consistency_helper"
require File.join(Rails.root, 'app/jobs/consistency_check.rb')

class AAAPreConsistency < ActionDispatch::IntegrationTest
fixtures :all
Expand All @@ -7,10 +8,10 @@ def test_resubmit_fixtures
login_king
wait_for_scheduler_start

consistency_check
ConsistencyCheckJob.new.perform

resubmit_all_fixtures

consistency_check
ConsistencyCheckJob.new.perform
end
end
5 changes: 3 additions & 2 deletions src/api/test/functional/zzz_post_consistency_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + "/..") + "/test_consistency_helper"
require File.join(Rails.root, 'app/jobs/consistency_check.rb')

class ZZZPostConsistency < ActionDispatch::IntegrationTest
require 'source_controller'
Expand All @@ -13,11 +14,11 @@ def test_resubmit_fixtures
login_king
wait_for_scheduler_start

consistency_check
ConsistencyCheckJob.new.perform

resubmit_all_fixtures

consistency_check
ConsistencyCheckJob.new.perform
end

def test_check_maintenance_project
Expand Down
5 changes: 1 addition & 4 deletions src/api/test/test_consistency_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
require 'source_controller'

#
# Add all kind of data consistency checks here. It runs before and after all functional tests
# to detect any kind of data corruption due to some other code
# code which is supposed to be run at multiple stages during the test suite run
#

include AdminHelper

def resubmit_all_fixtures
# this just reads and writes again the meta data. 1st run the fixtures and on 2nd all left
# overs from other other tests
Expand Down

0 comments on commit 1771853

Please sign in to comment.