|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | 3 | RSpec.describe Sentry::Cron::MonitorConfig do |
| 4 | + before do |
| 5 | + perform_basic_setup do |config| |
| 6 | + config.cron.default_checkin_margin = 1 |
| 7 | + config.cron.default_max_runtime = 30 |
| 8 | + config.cron.default_timezone = 'America/New_York' |
| 9 | + end |
| 10 | + end |
| 11 | + |
4 | 12 | describe '.from_crontab' do |
5 | 13 | it 'has correct attributes' do |
6 | 14 | subject = described_class.from_crontab( |
7 | 15 | '5 * * * *', |
8 | 16 | checkin_margin: 10, |
9 | | - max_runtime: 30, |
| 17 | + max_runtime: 20, |
10 | 18 | timezone: 'Europe/Vienna' |
11 | 19 | ) |
12 | 20 |
|
13 | 21 | expect(subject.schedule).to be_a(Sentry::Cron::MonitorSchedule::Crontab) |
14 | 22 | expect(subject.schedule.value).to eq('5 * * * *') |
15 | 23 | expect(subject.checkin_margin).to eq(10) |
16 | | - expect(subject.max_runtime).to eq(30) |
| 24 | + expect(subject.max_runtime).to eq(20) |
17 | 25 | expect(subject.timezone).to eq('Europe/Vienna') |
18 | 26 | end |
| 27 | + |
| 28 | + it 'fills in correct defaults from cron configuration' do |
| 29 | + subject = described_class.from_crontab('5 * * * *') |
| 30 | + |
| 31 | + expect(subject.schedule).to be_a(Sentry::Cron::MonitorSchedule::Crontab) |
| 32 | + expect(subject.schedule.value).to eq('5 * * * *') |
| 33 | + expect(subject.checkin_margin).to eq(1) |
| 34 | + expect(subject.max_runtime).to eq(30) |
| 35 | + expect(subject.timezone).to eq('America/New_York') |
| 36 | + end |
19 | 37 | end |
20 | 38 |
|
21 | 39 | describe '.from_interval' do |
|
28 | 46 | 5, |
29 | 47 | :hour, |
30 | 48 | checkin_margin: 10, |
31 | | - max_runtime: 30, |
| 49 | + max_runtime: 20, |
32 | 50 | timezone: 'Europe/Vienna' |
33 | 51 | ) |
34 | 52 |
|
35 | 53 | expect(subject.schedule).to be_a(Sentry::Cron::MonitorSchedule::Interval) |
36 | 54 | expect(subject.schedule.value).to eq(5) |
37 | 55 | expect(subject.schedule.unit).to eq(:hour) |
38 | 56 | expect(subject.checkin_margin).to eq(10) |
39 | | - expect(subject.max_runtime).to eq(30) |
| 57 | + expect(subject.max_runtime).to eq(20) |
40 | 58 | expect(subject.timezone).to eq('Europe/Vienna') |
41 | 59 | end |
| 60 | + |
| 61 | + it 'fills in correct defaults from cron configuration' do |
| 62 | + subject = described_class.from_interval(5, :minute) |
| 63 | + |
| 64 | + expect(subject.schedule).to be_a(Sentry::Cron::MonitorSchedule::Interval) |
| 65 | + expect(subject.schedule.value).to eq(5) |
| 66 | + expect(subject.schedule.unit).to eq(:minute) |
| 67 | + expect(subject.checkin_margin).to eq(1) |
| 68 | + expect(subject.max_runtime).to eq(30) |
| 69 | + expect(subject.timezone).to eq('America/New_York') |
| 70 | + end |
42 | 71 | end |
43 | 72 |
|
44 | 73 | describe '#to_hash' do |
45 | 74 | it 'returns hash with correct attributes for crontab' do |
46 | 75 | subject = described_class.from_crontab( |
47 | 76 | '5 * * * *', |
48 | 77 | checkin_margin: 10, |
49 | | - max_runtime: 30, |
| 78 | + max_runtime: 20, |
50 | 79 | timezone: 'Europe/Vienna' |
51 | 80 | ) |
52 | 81 |
|
53 | 82 | hash = subject.to_hash |
54 | 83 | expect(hash).to eq({ |
55 | 84 | schedule: { type: :crontab, value: '5 * * * *' }, |
56 | 85 | checkin_margin: 10, |
57 | | - max_runtime: 30, |
| 86 | + max_runtime: 20, |
58 | 87 | timezone: 'Europe/Vienna' |
59 | 88 | }) |
60 | 89 | end |
|
64 | 93 | 5, |
65 | 94 | :hour, |
66 | 95 | checkin_margin: 10, |
67 | | - max_runtime: 30, |
| 96 | + max_runtime: 20, |
68 | 97 | timezone: 'Europe/Vienna' |
69 | 98 | ) |
70 | 99 |
|
71 | 100 | hash = subject.to_hash |
72 | 101 | expect(hash).to eq({ |
73 | 102 | schedule: { type: :interval, value: 5, unit: :hour }, |
74 | 103 | checkin_margin: 10, |
75 | | - max_runtime: 30, |
| 104 | + max_runtime: 20, |
76 | 105 | timezone: 'Europe/Vienna' |
77 | 106 | }) |
78 | 107 | end |
|
0 commit comments