scheduler_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/concerns/has_xss_sanitized_note_examples'
  4. require 'models/concerns/has_timeplan_examples'
  5. RSpec.describe Scheduler do
  6. let!(:failed_job) { create(:scheduler, status: 'error', active: false) }
  7. it_behaves_like 'HasXssSanitizedNote', model_factory: :scheduler
  8. it_behaves_like 'HasTimeplan'
  9. describe '.failed_jobs' do
  10. it 'does list failed jobs' do
  11. expect(described_class.failed_jobs).to include(failed_job)
  12. end
  13. end
  14. describe '.restart_failed_jobs' do
  15. it 'does restart failed jobs' do
  16. described_class.restart_failed_jobs
  17. expect(failed_job.reload.active).to be true
  18. end
  19. end
  20. describe '.runs_as_persistent_loop?' do
  21. context 'when job is default' do
  22. let(:job) { create(:scheduler) }
  23. it 'does not run as loop' do
  24. expect(job.runs_as_persistent_loop?).to be false
  25. end
  26. end
  27. context 'when job period is > 5 min' do
  28. let(:job) { create(:scheduler, period: 6.minutes) }
  29. it 'does run as loop' do
  30. expect(job.runs_as_persistent_loop?).to be false
  31. end
  32. end
  33. context 'when job period is <= 5 min' do
  34. let(:job) { create(:scheduler, period: 5.minutes) }
  35. it 'does run as loop' do
  36. expect(job.runs_as_persistent_loop?).to be true
  37. end
  38. end
  39. end
  40. end