resque_unit 0.4.8 → 1.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -11
- data/lib/resque_unit/assertions.rb +9 -5
- data/lib/resque_unit/resque/test_extensions.rb +66 -0
- data/lib/resque_unit/resque.rb +15 -224
- data/lib/resque_unit/scheduler_assertions.rb +21 -7
- data/lib/resque_unit.rb +2 -5
- data/lib/resque_unit_scheduler.rb +3 -2
- data/test/redis_test.rb +11 -0
- data/test/resque_test.rb +18 -18
- data/test/resque_unit_scheduler_test.rb +76 -74
- data/test/resque_unit_test.rb +121 -138
- data/test/test_helper.rb +4 -6
- metadata +56 -15
- data/lib/resque_unit/errors.rb +0 -17
- data/lib/resque_unit/helpers.rb +0 -57
- data/lib/resque_unit/plugin.rb +0 -70
- data/lib/resque_unit/scheduler.rb +0 -40
@@ -1,230 +1,232 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'resque_unit_scheduler'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe Resque do
|
5
|
+
include ResqueUnit::Assertions
|
6
|
+
include ResqueUnit::SchedulerAssertions
|
7
|
+
|
8
|
+
before do
|
7
9
|
Resque.reset!
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
describe "A task that schedules a resque job in 5 minutes" do
|
13
|
+
before { Resque.enqueue_in(600, MediumPriorityJob) }
|
14
|
+
it "passes the assert_queued(job) assertion" do
|
13
15
|
assert_queued(MediumPriorityJob)
|
14
16
|
end
|
15
17
|
|
16
|
-
|
18
|
+
it "passes the assert_queued_in(600, job) assertion" do
|
17
19
|
assert_queued_in(600, MediumPriorityJob)
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
it "fails the assert_queued_in(300, job) assertion" do
|
23
|
+
assert_raises Minitest::Assertion do
|
22
24
|
assert_queued_in(300, MediumPriorityJob)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
28
|
+
it "passes the assert_not_queued_in(300, job) assertion" do
|
27
29
|
assert_not_queued_in(300, MediumPriorityJob)
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
describe "and then the job is removed with #remove_delayed" do
|
33
|
+
before do
|
32
34
|
Resque.remove_delayed(MediumPriorityJob)
|
33
35
|
end
|
34
|
-
|
36
|
+
it "passes the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
|
35
37
|
assert_not_queued_at(300, MediumPriorityJob)
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
it "fails the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
41
|
+
assert_raises Minitest::Assertion do
|
40
42
|
assert_queued_at(300, MediumPriorityJob)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
describe "A task that schedules a resque job in 5 minutes with arguments" do
|
49
|
+
before { Resque.enqueue_in(600, JobWithArguments, 1, "test") }
|
50
|
+
it "passes the assert_queued_in(600, JobWithArguments) assertion" do
|
49
51
|
assert_queued_in(600, JobWithArguments)
|
50
52
|
end
|
51
53
|
|
52
|
-
|
54
|
+
it "passes the assert_queued_in(600, JobWithArguments, [1, 'test']) assertion" do
|
53
55
|
assert_queued_in(600, JobWithArguments, [1, 'test'])
|
54
56
|
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
+
it "fails the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
|
59
|
+
assert_raises Minitest::Assertion do
|
58
60
|
assert_queued_in(600, JobWithArguments, [2, 'test'])
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
+
describe "and then the job is removed with #remove_delayed" do
|
65
|
+
before do
|
64
66
|
Resque.remove_delayed(JobWithArguments, 1, 'test')
|
65
67
|
end
|
66
|
-
|
68
|
+
it "passes the assert_not_queued_at(@time, JobWithArguments, 1, 'test') assertion" do
|
67
69
|
assert_not_queued_at(600, JobWithArguments, 1, 'test')
|
68
70
|
end
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
+
it "fails the assert_queued_at(@time, JobWithArguments, 1, 'test') assertion" do
|
73
|
+
assert_raises Minitest::Assertion do
|
72
74
|
assert_queued_at(600, JobWithArguments, 1, 'test')
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
+
describe "and a job of the same class but with different arguments is removed with #remove_delayed" do
|
80
|
+
before do
|
79
81
|
Resque.remove_delayed(JobWithArguments, 2, 'test')
|
80
82
|
end
|
81
|
-
|
83
|
+
it "still passes the assert_queued_in(600, JobWithArguments) assertion" do
|
82
84
|
assert_queued_in(600, JobWithArguments)
|
83
85
|
end
|
84
86
|
|
85
|
-
|
87
|
+
it "still passes the assert_queued_in(600, JobWithArguments, [1, 'test']) assertion" do
|
86
88
|
assert_queued_in(600, JobWithArguments, [1, 'test'])
|
87
89
|
end
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
+
it "still fails the assert_queued_in(600, JobWithArguments, [2, 'test']) assertion" do
|
92
|
+
assert_raises Minitest::Assertion do
|
91
93
|
assert_queued_in(600, JobWithArguments, [2, 'test'])
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
+
describe "A task that schedules a resque job on Sept. 6, 2016 at 6am" do
|
100
|
+
before do
|
99
101
|
@time = Time.mktime(2016, 9, 6, 6)
|
100
102
|
Resque.enqueue_at(@time, MediumPriorityJob)
|
101
103
|
end
|
102
104
|
|
103
|
-
|
105
|
+
it "passes the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
104
106
|
assert_queued_at(@time, MediumPriorityJob)
|
105
107
|
end
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
+
it "fails the assert_queued_at(@time - 100, MediumPriorityJob) assertion" do
|
110
|
+
assert_raises Minitest::Assertion do
|
109
111
|
assert_queued_at(@time - 100, MediumPriorityJob)
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
113
|
-
|
115
|
+
it "passes the assert_not_queued_at(@time - 100, MediumPriorityJob) assertion" do
|
114
116
|
assert_not_queued_at(@time - 100, MediumPriorityJob)
|
115
117
|
end
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
describe "and then the job is removed with #remove_delayed" do
|
120
|
+
before do
|
119
121
|
Resque.remove_delayed(MediumPriorityJob)
|
120
122
|
end
|
121
|
-
|
123
|
+
it "passes the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
|
122
124
|
assert_not_queued_at(@time, MediumPriorityJob)
|
123
125
|
end
|
124
126
|
|
125
|
-
|
126
|
-
|
127
|
+
it "fails the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
128
|
+
assert_raises Minitest::Assertion do
|
127
129
|
assert_queued_at(@time, MediumPriorityJob)
|
128
130
|
end
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
132
|
-
|
133
|
-
|
134
|
+
describe "and then the job is removed with #remove_delayed_job_from_timestamp" do
|
135
|
+
before do
|
134
136
|
Resque.remove_delayed_job_from_timestamp(@time, MediumPriorityJob)
|
135
137
|
end
|
136
138
|
|
137
|
-
|
139
|
+
it "passes the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
|
138
140
|
assert_not_queued_at(@time, MediumPriorityJob)
|
139
141
|
end
|
140
142
|
|
141
|
-
|
142
|
-
|
143
|
+
it "fails the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
144
|
+
assert_raises Minitest::Assertion do
|
143
145
|
assert_queued_at(@time, MediumPriorityJob)
|
144
146
|
end
|
145
147
|
end
|
146
148
|
end
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
+
describe "and then the job is removed with #remove_delayed_job_from_timestamp with timestamp specified in another timezone" do
|
151
|
+
before do
|
150
152
|
Resque.remove_delayed_job_from_timestamp(@time.utc, MediumPriorityJob)
|
151
153
|
end
|
152
154
|
|
153
|
-
|
155
|
+
it "passes the assert_not_queued_at(@time, MediumPriorityJob) assertion" do
|
154
156
|
assert_not_queued_at(@time, MediumPriorityJob)
|
155
157
|
end
|
156
158
|
|
157
|
-
|
158
|
-
|
159
|
+
it "fails the assert_queued_at(@time, MediumPriorityJob) assertion" do
|
160
|
+
assert_raises Minitest::Assertion do
|
159
161
|
assert_queued_at(@time, MediumPriorityJob)
|
160
162
|
end
|
161
163
|
end
|
162
164
|
end
|
163
165
|
end
|
164
166
|
|
165
|
-
|
166
|
-
|
167
|
+
describe "A task that schedules a resque job with arguments on on Sept. 6, 2016 at 6am" do
|
168
|
+
before do
|
167
169
|
@time = Time.mktime(2016, 9, 6, 6)
|
168
170
|
Resque.enqueue_at(@time, JobWithArguments, 1, "test")
|
169
171
|
end
|
170
172
|
|
171
|
-
|
173
|
+
it "passes the assert_queued_at(@time, JobWithArguments, *args) assertion" do
|
172
174
|
assert_queued_at(@time, JobWithArguments, [1, "test"])
|
173
175
|
end
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
+
it "fails the assert_queued_at(@time - 100, JobWithArguments, *args) assertion" do
|
178
|
+
assert_raises Minitest::Assertion do
|
177
179
|
assert_queued_at(@time - 100, JobWithArguments, [1, "test"])
|
178
180
|
end
|
179
181
|
end
|
180
182
|
|
181
|
-
|
183
|
+
it "passes the assert_not_queued_at(@time - 100, JobWithArguments, *args) assertion" do
|
182
184
|
assert_not_queued_at(@time - 100, JobWithArguments, [1, "test"])
|
183
185
|
end
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
+
describe "and then the job is removed with #remove_delayed" do
|
188
|
+
before do
|
187
189
|
Resque.remove_delayed(JobWithArguments, 1, "test")
|
188
190
|
end
|
189
191
|
|
190
|
-
|
192
|
+
it "passes the assert_not_queued_at(@time, JobWithArguments, *args) assertion" do
|
191
193
|
assert_not_queued_at(@time, JobWithArguments, [1, "test"])
|
192
194
|
end
|
193
195
|
|
194
|
-
|
195
|
-
|
196
|
+
it "fails the assert_queued_at(@time, JobWithArguments, *args) assertion" do
|
197
|
+
assert_raises Minitest::Assertion do
|
196
198
|
assert_queued_at(@time, JobWithArguments, [1, "test"])
|
197
199
|
end
|
198
200
|
end
|
199
201
|
end
|
200
202
|
|
201
|
-
|
202
|
-
|
203
|
+
describe "and then the job is removed with #remove_delayed_job_from_timestamp" do
|
204
|
+
before do
|
203
205
|
Resque.remove_delayed_job_from_timestamp(@time, JobWithArguments, 1, "test")
|
204
206
|
end
|
205
207
|
|
206
|
-
|
208
|
+
it "pass the assert_not_queued_at(@time, JobWithArguments, *args) assertion" do
|
207
209
|
assert_not_queued_at(@time, JobWithArguments, [1, "test"])
|
208
210
|
end
|
209
211
|
|
210
|
-
|
211
|
-
|
212
|
+
it "fail the assert_queued_at(@time, MediumPriorityJob, *args) assertion" do
|
213
|
+
assert_raises Minitest::Assertion do
|
212
214
|
assert_queued_at(@time, JobWithArguments, [1, "test"])
|
213
215
|
end
|
214
216
|
end
|
215
217
|
end
|
216
218
|
|
217
|
-
|
218
|
-
|
219
|
+
describe "and then the job is removed with #remove_delayed_job_from_timestamp with timestamp in another timezone" do
|
220
|
+
before do
|
219
221
|
Resque.remove_delayed_job_from_timestamp(@time.utc, JobWithArguments, 1, "test")
|
220
222
|
end
|
221
223
|
|
222
|
-
|
224
|
+
it "passes the assert_not_queued_at(@time, JobWithArguments, *args) assertion" do
|
223
225
|
assert_not_queued_at(@time, JobWithArguments, [1, "test"])
|
224
226
|
end
|
225
227
|
|
226
|
-
|
227
|
-
|
228
|
+
it "fails the assert_queued_at(@time, MediumPriorityJob, *args) assertion" do
|
229
|
+
assert_raises Minitest::Assertion do
|
228
230
|
assert_queued_at(@time, JobWithArguments, [1, "test"])
|
229
231
|
end
|
230
232
|
end
|