From b9c24748a9fa9f4de23cd051f3afbc4b03f0911e Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 26 Apr 2016 11:30:46 +0200 Subject: [PATCH] Added reset of UserInfo.current_user_id for background jobs and transactions. --- app/models/scheduler.rb | 47 +++++------ app/models/transaction/background_job.rb | 6 +- app/models/transaction/clearbit_enrichment.rb | 1 + test/controllers/search_controller_test.rb | 4 +- test/integration/clearbit_test.rb | 22 ++--- test/integration/elasticsearch_test.rb | 3 +- test/integration/report_test.rb | 3 +- test/integration/slack_test.rb | 22 ++--- test/integration_test_helper.rb | 3 + test/test_helper.rb | 18 +--- test/unit/email_signatur_detection_test.rb | 6 +- test/unit/history_test.rb | 2 +- test/unit/online_notifiaction_test.rb | 37 +++------ test/unit/ticket_notification_test.rb | 83 +++++++------------ test/unit/ticket_sla_test.rb | 30 +++---- 15 files changed, 110 insertions(+), 177 deletions(-) diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index f8c003920..8bfba5e50 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -1,5 +1,5 @@ # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ -# rubocop:disable Rails/Output + class Scheduler < ApplicationModel # rubocop:disable Style/ClassVars @@ -114,9 +114,25 @@ class Scheduler < ApplicationModel end end - def self.worker - wait = 8 + def self.worker(foreground = false) + # used for tests + if foreground + original_user_id = UserInfo.current_user_id + UserInfo.current_user_id = nil + loop do + success, failure = Delayed::Worker.new.work_off + if failure != 0 + raise "ERROR: #{failure} failed background jobs: #{Delayed::Job.where('last_error IS NOT NULL').inspect}" + end + break if success == 0 + end + UserInfo.current_user_id = original_user_id + return + end + + # used for production + wait = 8 Thread.new { sleep wait @@ -126,6 +142,7 @@ class Scheduler < ApplicationModel result = nil realtime = Benchmark.realtime do + logger.debug "*** worker thread, #{Delayed::Job.all.count} in queue" result = Delayed::Worker.new.work_off end @@ -145,28 +162,4 @@ class Scheduler < ApplicationModel end - def self.check(name, time_warning = 10, time_critical = 20) - time_warning_time = Time.zone.now - time_warning.minutes - time_critical_time = Time.zone.now - time_critical.minutes - scheduler = Scheduler.find_by( name: name ) - if !scheduler - puts "CRITICAL - no such scheduler jobs '#{name}'" - return true - end - logger.debug scheduler.inspect - if !scheduler.last_run - puts "CRITICAL - scheduler jobs never started '#{name}'" - exit 2 - end - if scheduler.last_run < time_critical_time - puts "CRITICAL - scheduler jobs was not running in last '#{time_critical}' minutes - last run at '#{scheduler.last_run}' '#{name}'" - exit 2 - end - if scheduler.last_run < time_warning_time - puts "CRITICAL - scheduler jobs was not running in last '#{time_warning}' minutes - last run at '#{scheduler.last_run}' '#{name}'" - exit 2 - end - puts "ok - scheduler jobs was running at '#{scheduler.last_run}' '#{name}'" - exit 0 - end end diff --git a/app/models/transaction/background_job.rb b/app/models/transaction/background_job.rb index c273f5211..fcb580b44 100644 --- a/app/models/transaction/background_job.rb +++ b/app/models/transaction/background_job.rb @@ -24,12 +24,12 @@ class Transaction::BackgroundJob Setting.where(area: 'Transaction::Backend').order(:name).each {|setting| backend = Setting.get(setting.name) begin - UserInfo.current_user_id = 1 + UserInfo.current_user_id = nil integration = Kernel.const_get(backend).new(@item, @params) integration.perform rescue => e - logger.error 'ERROR: ' + setting.inspect - logger.error 'ERROR: ' + e.inspect + Rails.logger.error 'ERROR: ' + setting.inspect + Rails.logger.error 'ERROR: ' + e.inspect end } end diff --git a/app/models/transaction/clearbit_enrichment.rb b/app/models/transaction/clearbit_enrichment.rb index 6c87e42c6..80d8fb78a 100644 --- a/app/models/transaction/clearbit_enrichment.rb +++ b/app/models/transaction/clearbit_enrichment.rb @@ -47,6 +47,7 @@ class Transaction::ClearbitEnrichment end def self.sync_user(user) + UserInfo.current_user_id = 1 return if user.email.empty? data = fetch(user.email) diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb index ebe6e18b8..9bb9f1b6b 100644 --- a/test/controllers/search_controller_test.rb +++ b/test/controllers/search_controller_test.rb @@ -177,9 +177,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest system('rake searchindex:rebuild') # execute background jobs - # execute background jobs - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) sleep 6 end diff --git a/test/integration/clearbit_test.rb b/test/integration/clearbit_test.rb index 54171cb0d..496b14816 100644 --- a/test/integration/clearbit_test.rb +++ b/test/integration/clearbit_test.rb @@ -48,7 +48,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer1) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer1.id)) @@ -76,7 +76,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer2) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer2.id)) @@ -99,7 +99,7 @@ class ClearbitTest < ActiveSupport::TestCase ) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer2.id)) @@ -111,7 +111,7 @@ class ClearbitTest < ActiveSupport::TestCase assert_equal('Norsk-Data-Straße 1, 61352 Bad Homburg vor der Höhe, Germany', customer2_lookup.address) Transaction::ClearbitEnrichment.sync_user(customer2) - Delayed::Worker.new.work_off + Scheduler.worker(true) customer2_lookup = User.lookup(id: customer2.id) @@ -127,7 +127,7 @@ class ClearbitTest < ActiveSupport::TestCase ) Transaction::ClearbitEnrichment.sync_user(customer2) - Delayed::Worker.new.work_off + Scheduler.worker(true) customer2_lookup = User.lookup(id: customer2.id) @@ -142,7 +142,7 @@ class ClearbitTest < ActiveSupport::TestCase ) Transaction::ClearbitEnrichment.sync_user(customer2) - Delayed::Worker.new.work_off + Scheduler.worker(true) customer2_lookup = User.lookup(id: customer2.id) @@ -168,7 +168,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer3) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert_not(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer3.id)) @@ -199,7 +199,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer4) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer4.id)) @@ -228,7 +228,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer5) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer5.id)) @@ -259,7 +259,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer6) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert_not(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer6.id)) @@ -322,7 +322,7 @@ class ClearbitTest < ActiveSupport::TestCase assert(customer1) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ExternalSync.find_by(source: 'clearbit', object: 'User', o_id: customer1.id)) diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index 827eed6e2..d2ed86870 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -215,8 +215,7 @@ class ElasticsearchTest < ActiveSupport::TestCase ) # execute background jobs - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) sleep 6 diff --git a/test/integration/report_test.rb b/test/integration/report_test.rb index 1a9c7b3dd..813bfd266 100644 --- a/test/integration/report_test.rb +++ b/test/integration/report_test.rb @@ -240,8 +240,7 @@ class ReportTest < ActiveSupport::TestCase ) # execute background jobs - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) sleep 6 diff --git a/test/integration/slack_test.rb b/test/integration/slack_test.rb index a9fd98ba2..a70a91844 100644 --- a/test/integration/slack_test.rb +++ b/test/integration/slack_test.rb @@ -69,7 +69,7 @@ class SlackTest < ActiveSupport::TestCase ) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(0, slack_check(channel, hash)) @@ -78,7 +78,7 @@ class SlackTest < ActiveSupport::TestCase ticket1.save Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(0, slack_check(channel, hash)) @@ -107,7 +107,7 @@ class SlackTest < ActiveSupport::TestCase ) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(1, slack_check(channel, hash)) @@ -119,7 +119,7 @@ class SlackTest < ActiveSupport::TestCase ticket2.save Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(1, slack_check(channel, hash)) @@ -129,7 +129,7 @@ class SlackTest < ActiveSupport::TestCase ticket2.save Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(2, slack_check(channel, hash)) @@ -137,7 +137,7 @@ class SlackTest < ActiveSupport::TestCase Ticket.process_pending Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(3, slack_check(channel, hash)) @@ -145,7 +145,7 @@ class SlackTest < ActiveSupport::TestCase Ticket.process_pending Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(3, slack_check(channel, hash)) @@ -188,7 +188,7 @@ class SlackTest < ActiveSupport::TestCase ) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(0, slack_check(channel, hash)) @@ -197,7 +197,7 @@ class SlackTest < ActiveSupport::TestCase ticket3.save Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(0, slack_check(channel, hash)) @@ -226,7 +226,7 @@ class SlackTest < ActiveSupport::TestCase ) Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(1, slack_check(channel, hash)) @@ -238,7 +238,7 @@ class SlackTest < ActiveSupport::TestCase ticket4.save Observer::Transaction.commit - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if message exists assert_equal(0, slack_check(channel, hash)) diff --git a/test/integration_test_helper.rb b/test/integration_test_helper.rb index 5c596be20..209b799f8 100644 --- a/test/integration_test_helper.rb +++ b/test/integration_test_helper.rb @@ -18,6 +18,9 @@ class ActiveSupport::TestCase # clear cache Cache.clear + # remove background jobs + Delayed::Job.destroy_all + # set current user UserInfo.current_user_id = nil end diff --git a/test/test_helper.rb b/test/test_helper.rb index b9bbf3694..8d98c6c4b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,9 +24,6 @@ class ActiveSupport::TestCase load "#{Rails.root}/db/seeds.rb" load "#{Rails.root}/test/fixtures/seeds.rb" - # proccess background jobs - Delayed::Worker.new.work_off - # set system mode to done / to activate Setting.set('system_init_done', true) @@ -35,21 +32,12 @@ class ActiveSupport::TestCase # clear cache Cache.clear + # remove background jobs + Delayed::Job.destroy_all + # set current user UserInfo.current_user_id = nil end - # cleanup jobs - def teardown - - # check if jobs are proccessed - return if Delayed::Job.all.empty? - - Delayed::Job.where('failed_at != NULL').each {|job| - assert( false, "not processable job #{job.inspect}" ) - } - Delayed::Job.all.destroy_all - end - # Add more helper methods to be used by all tests here... end diff --git a/test/unit/email_signatur_detection_test.rb b/test/unit/email_signatur_detection_test.rb index c8844760c..533c6c822 100644 --- a/test/unit/email_signatur_detection_test.rb +++ b/test/unit/email_signatur_detection_test.rb @@ -73,7 +73,7 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase ticket1, article1, user1, mail = Channel::EmailParser.new.process({}, raw_email) assert(ticket1) assert(article1) - Delayed::Worker.new.work_off + Scheduler.worker(true) # process email II file = File.open("#{Rails.root}/test/fixtures/email_signature_detection/client_a_2.txt", 'rb') @@ -81,7 +81,7 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase ticket2, article2, user2, mail = Channel::EmailParser.new.process({}, raw_email) assert(ticket2) assert(article2) - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if user2 has a signature_detection value user2 = User.find(user2.id) @@ -93,7 +93,7 @@ class EmailSignaturDetectionTest < ActiveSupport::TestCase ticket3, article3, user3, mail = Channel::EmailParser.new.process({}, raw_email) assert(ticket3) assert(article3) - Delayed::Worker.new.work_off + Scheduler.worker(true) # check if article3 has a signature_detection value article3 = Ticket::Article.find(article3.id) diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index 29e147506..73590bcff 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -175,7 +175,7 @@ class HistoryTest < ActiveSupport::TestCase Observer::Transaction.commit # execute background jobs - Delayed::Worker.new.work_off + Scheduler.worker(true) # remember ticket tickets.push ticket diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index c1ad1fa05..e36c15274 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -62,8 +62,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already closed assert(OnlineNotification.all_seen?('Ticket', ticket1.id)) @@ -81,8 +80,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket1.id)) @@ -119,8 +117,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already closed assert(!OnlineNotification.all_seen?('Ticket', ticket2.id)) @@ -138,8 +135,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket2.id)) @@ -175,8 +171,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already new assert(!OnlineNotification.all_seen?('Ticket', ticket3.id)) @@ -194,8 +189,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already closed assert(OnlineNotification.all_seen?('Ticket', ticket3.id)) @@ -219,8 +213,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already closed but an follow up arrived later assert(!OnlineNotification.all_seen?('Ticket', ticket3.id)) @@ -258,8 +251,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already new assert(!OnlineNotification.all_seen?('Ticket', ticket4.id)) @@ -277,8 +269,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket4.id)) @@ -314,8 +305,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already new assert(!OnlineNotification.all_seen?('Ticket', ticket5.id)) @@ -333,8 +323,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket5.id)) @@ -348,7 +337,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase ticket_id: tickets[1].id, user_id: 1, ) - Delayed::Worker.new.work_off + Scheduler.worker(true) notifications = OnlineNotification.list_by_object('Ticket', tickets[0].id) assert(!notifications.empty?, 'should have notifications') @@ -366,7 +355,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert(!found, 'Ticket destroyed') # check if notifications for ticket still exist - Delayed::Worker.new.work_off + Scheduler.worker(true) notifications = OnlineNotification.list_by_object('Ticket', ticket_id) assert(notifications.empty?, 'still notifications for destroyed ticket available') } diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 4de9a0d46..6339634ea 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -88,8 +88,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = nil Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -123,8 +122,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = true Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -161,8 +159,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = true Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -175,8 +172,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -197,8 +193,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to not to agent1 but to agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -222,8 +217,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to not to agent1 but to agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -256,8 +250,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ticket2, 'ticket created') # verify notifications to no one @@ -272,8 +265,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to no one assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) @@ -287,8 +279,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 and not to agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) @@ -321,8 +312,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) assert(ticket3, 'ticket created') # verify notifications to agent1 and not to agent2 @@ -337,8 +327,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to no one assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) @@ -352,8 +341,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 and not to agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) @@ -365,8 +353,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications not to agent1 and not to agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) @@ -412,7 +399,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit(disable_notification: true) - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -465,8 +452,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = false Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -479,8 +465,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) @@ -513,8 +498,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) @@ -527,8 +511,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) @@ -561,8 +544,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) @@ -575,8 +557,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) @@ -627,8 +608,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = false Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, agent1, 'email'), ticket4.id) @@ -641,8 +621,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, agent1, 'email'), ticket4.id) @@ -693,8 +672,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = false Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket5, agent1, 'email'), ticket5.id) @@ -707,8 +685,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket5, agent1, 'email'), ticket5.id) @@ -760,8 +737,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = false Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'email'), ticket6.id) @@ -776,8 +752,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'email'), ticket6.id) @@ -839,8 +814,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Rails.configuration.webserver_is_active = false Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'email'), ticket7.id) @@ -855,8 +829,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # execute object transaction Observer::Transaction.commit - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) # verify notifications to agent1 + agent2 assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'email'), ticket7.id) diff --git a/test/unit/ticket_sla_test.rb b/test/unit/ticket_sla_test.rb index 0a079db5a..4122c7429 100644 --- a/test/unit/ticket_sla_test.rb +++ b/test/unit/ticket_sla_test.rb @@ -74,8 +74,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -92,8 +91,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -155,8 +153,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.escalation_time verify 2' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 10:30:00 UTC', 'ticket.first_response_escal_date verify 2' ) @@ -601,8 +598,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-03-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -691,8 +687,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -730,8 +725,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-10-21 08:00:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -885,8 +879,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time.gmtime.to_s, '2013-06-04 13:30:00 UTC', 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 11:30:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -982,8 +975,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 13:00:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -1110,8 +1102,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.first_response_escal_date verify 1' ) @@ -1254,8 +1245,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - #puts Delayed::Job.all.inspect - Delayed::Worker.new.work_off + Scheduler.worker(true) ticket = Ticket.find(ticket.id) assert_equal( ticket.escalation_time, nil, 'ticket.escalation_time verify 1' ) assert_equal( ticket.first_response_escal_date.gmtime.to_s, '2013-06-04 12:30:00 UTC', 'ticket.first_response_escal_date verify 1' )