resque_unit 0.4.8 → 1.0.0.beta.1
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.rb +2 -4
- data/lib/resque_unit/assertions.rb +9 -5
- data/lib/resque_unit/resque.rb +15 -224
- data/lib/resque_unit/resque/test_extensions.rb +68 -0
- data/lib/resque_unit/scheduler_assertions.rb +21 -7
- 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 +67 -11
- data/lib/resque_unit/errors.rb +0 -17
- data/lib/resque_unit/plugin.rb +0 -70
- data/lib/resque_unit/scheduler.rb +0 -40
@@ -1,7 +1,8 @@
|
|
1
|
-
require 'resque_unit
|
1
|
+
require 'resque_unit'
|
2
|
+
require 'resque-scheduler'
|
2
3
|
require 'resque_unit/scheduler_assertions'
|
3
4
|
|
4
|
-
if defined?(Test::Unit)
|
5
|
+
if defined?(Test::Unit::TestCase)
|
5
6
|
Test::Unit::TestCase.send(:include, ResqueUnit::SchedulerAssertions)
|
6
7
|
end
|
7
8
|
|
data/test/redis_test.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Redis do
|
4
|
+
it "uses a real Redis connection by default" do
|
5
|
+
redis = Redis.current
|
6
|
+
refute_equal Redis::Connection::Memory, redis.client.driver
|
7
|
+
|
8
|
+
redis = Redis.new
|
9
|
+
refute_equal Redis::Connection::Memory, redis.client.driver
|
10
|
+
end
|
11
|
+
end
|
data/test/resque_test.rb
CHANGED
@@ -1,60 +1,60 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
describe Resque do
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
def setup
|
4
|
+
before do
|
6
5
|
Resque.reset!
|
7
6
|
end
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
describe "with one queued job" do
|
9
|
+
before do
|
11
10
|
Resque.enqueue(MediumPriorityJob, "some args")
|
12
11
|
@job_payload = {"args"=>["some args"], "class"=>"MediumPriorityJob"}
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
it "returns the job payload when peek method called with count equal 1" do
|
16
15
|
assert_equal @job_payload, Resque.peek(MediumPriorityJob.queue, 0, 1)
|
17
16
|
end
|
18
17
|
|
19
|
-
|
18
|
+
it "returns an array of jobs' payloads when peek method called with count different than 1" do
|
20
19
|
assert_equal [@job_payload], Resque.peek(MediumPriorityJob.queue, 0, 5)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
|
23
|
+
describe "with few queued jobs" do
|
24
|
+
before do
|
26
25
|
Resque.enqueue(MediumPriorityJob, "1")
|
27
26
|
Resque.enqueue(MediumPriorityJob, "2")
|
28
27
|
Resque.enqueue(MediumPriorityJob, "3")
|
29
28
|
end
|
30
29
|
|
31
|
-
|
30
|
+
it "returns jobs' payloads 2 and 3 when peek method called with start equal 1 and count equal 2" do
|
32
31
|
assert_equal [["2"], ["3"]], Resque.peek(MediumPriorityJob.queue, 1, 2).map{|h| h["args"]}
|
33
32
|
end
|
34
33
|
|
35
|
-
|
34
|
+
it "returns an empty array when peek method called with start higher than queue size" do
|
36
35
|
assert_equal [], Resque.peek(MediumPriorityJob.queue, 4, 2)
|
37
36
|
end
|
38
37
|
|
39
|
-
|
40
|
-
|
38
|
+
it "returns all jobs' payloads when peek method called with count equal 0" do
|
39
|
+
# This is the way Resque.peek works, so it's now the way resque-unit works!
|
40
|
+
assert_equal Resque.all(MediumPriorityJob.queue), Resque.peek(MediumPriorityJob.queue, 0, 0)
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
it "returns all jobs' payloads when all method called" do
|
44
44
|
assert Resque.all(MediumPriorityJob.queue).length == 3, "should return all 3 elements"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
describe "without queued jobs" do
|
49
|
+
it "returns nil when peek method called with count equal 1" do
|
50
50
|
assert_equal nil, Resque.peek(MediumPriorityJob.queue, 0, 1)
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
it "returns an empty array when peek method called with count not equal 1" do
|
54
54
|
assert_equal [], Resque.peek(MediumPriorityJob.queue, 0, 999)
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
it "returns an empty array when `all` is called" do
|
58
58
|
assert_equal [], Resque.all(MediumPriorityJob.queue)
|
59
59
|
end
|
60
60
|
end
|
@@ -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
|
data/test/resque_unit_test.rb
CHANGED
@@ -1,94 +1,94 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe ResqueUnit do
|
4
4
|
|
5
|
-
|
5
|
+
before do
|
6
6
|
# should probably happen automatically, but I haven't thought of a
|
7
7
|
# good way to hook setup() yet.
|
8
8
|
Resque.reset!
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
describe "A task that schedules a resque job implementing self.queue" do
|
12
|
+
before { Resque.enqueue(MediumPriorityJob) }
|
13
|
+
it "passes the assert_queued(job) assertion" do
|
14
14
|
assert_queued(MediumPriorityJob)
|
15
15
|
assert_job_created(MediumPriorityJob.queue, MediumPriorityJob)
|
16
16
|
assert_equal 1, Resque.queue(MediumPriorityJob.queue).length
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
describe "A task that explicitly is queued to a different queue" do
|
21
|
+
before { Resque.enqueue_to(:a_non_class_determined_queue, MediumPriorityJob) }
|
22
|
+
it "does not queue to the class-determined queue" do
|
23
23
|
assert_equal 0, Resque.queue(MediumPriorityJob.queue).length
|
24
24
|
end
|
25
|
-
|
25
|
+
it "queues to the explicly-stated queue" do
|
26
26
|
assert_equal 1, Resque.queue(:a_non_class_determined_queue).length
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
describe "A task that spawns multiple jobs on a single queue" do
|
31
|
+
before do
|
32
32
|
3.times {Resque.enqueue(HighPriorityJob)}
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
it "allows partial runs with explicit limit" do
|
36
36
|
assert_equal 3, Resque.queue(:high).length, 'failed setup'
|
37
|
-
Resque.run_for!(
|
37
|
+
Resque.run_for!(:high, 1)
|
38
38
|
assert_equal 2, Resque.queue(:high).length, 'failed to run just single job'
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it "allows full run with too-large explicit limit" do
|
42
42
|
assert_equal 3, Resque.queue(:high).length, 'failed setup'
|
43
|
-
Resque.run_for!(
|
43
|
+
Resque.run_for!(:high, 50)
|
44
44
|
assert_equal 0, Resque.queue(:high).length, 'failed to run all jobs'
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
it "allows full run with implicit limit" do
|
48
48
|
assert_equal 3, Resque.queue(:high).length, 'failed setup'
|
49
|
-
Resque.run_for!(
|
49
|
+
Resque.run_for!(:high)
|
50
50
|
assert_equal 0, Resque.queue(:high).length, 'failed to run all jobs'
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
54
|
+
describe "A task that schedules a resque job" do
|
55
|
+
before do
|
56
56
|
@returned = Resque.enqueue(LowPriorityJob)
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
it 'returns a value that evaluates to true' do
|
60
60
|
assert @returned
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
it "passes the assert_queued(job) assertion" do
|
64
64
|
assert_queued(LowPriorityJob)
|
65
65
|
end
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
it "fails the assert_not_queued(job) assertion" do
|
68
|
+
assert_raises Minitest::Assertion do
|
69
69
|
assert_not_queued(LowPriorityJob)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
73
|
+
it "has 1 job in the queue" do
|
74
74
|
assert_equal 1, Resque.size(:low)
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
|
77
|
+
describe ", when Resque.run! is called," do
|
78
|
+
before do
|
79
79
|
assert !LowPriorityJob.run?, "The job should not have been run yet"
|
80
80
|
Resque.run!
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
after do
|
84
84
|
LowPriorityJob.run = false
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
it "runs the job" do
|
88
88
|
assert LowPriorityJob.run?, "The job should have run"
|
89
89
|
end
|
90
90
|
|
91
|
-
|
91
|
+
it "clears the job from the queue" do
|
92
92
|
assert_not_queued(LowPriorityJob)
|
93
93
|
end
|
94
94
|
end
|
@@ -96,32 +96,24 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
96
96
|
# assert number of jobs?
|
97
97
|
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
teardown do
|
105
|
-
Resque.disable_hooks!
|
106
|
-
end
|
107
|
-
|
108
|
-
context "before, around, after, failure, after_enqueue" do
|
109
|
-
setup do
|
99
|
+
describe "A task that schedules a resque job with hooks" do
|
100
|
+
describe "before, around, after, failure, after_enqueue" do
|
101
|
+
before do
|
110
102
|
JobWithHooks.clear_markers
|
111
103
|
Resque.enqueue(JobWithHooks)
|
112
104
|
end
|
113
105
|
|
114
|
-
|
106
|
+
it "ran the after_enqueue hook" do
|
115
107
|
assert_queued(JobWithHooks)
|
116
108
|
assert(JobWithHooks.markers[:after_enqueue], 'no after_queue marker set')
|
117
109
|
end
|
118
110
|
|
119
|
-
|
111
|
+
it "ran the before_enqueue hook" do
|
120
112
|
assert(JobWithHooks.markers[:before_enqueue], 'no before_queue marker set')
|
121
113
|
assert_queued(JobWithHooks)
|
122
114
|
end
|
123
115
|
|
124
|
-
|
116
|
+
it "ran the before and after hooks during a run" do
|
125
117
|
Resque.run!
|
126
118
|
assert(JobWithHooks.markers[:before], 'no before marker set')
|
127
119
|
assert(JobWithHooks.markers[:around], 'no around marker set')
|
@@ -129,9 +121,9 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
129
121
|
assert(!JobWithHooks.markers[:failed], 'failed marker set, and it should not')
|
130
122
|
end
|
131
123
|
|
132
|
-
|
124
|
+
it "ran the before and failed hooks during a run" do
|
133
125
|
JobWithHooks.make_it_fail do
|
134
|
-
|
126
|
+
assert_raises(RuntimeError) do
|
135
127
|
Resque.run!
|
136
128
|
assert(JobWithHooks.markers[:before], 'no before marker set')
|
137
129
|
assert(JobWithHooks.markers[:around], 'no around marker set')
|
@@ -141,7 +133,7 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
141
133
|
end
|
142
134
|
end
|
143
135
|
|
144
|
-
|
136
|
+
it "does not call perform if the around hook raised Resque::Job::DontPerform" do
|
145
137
|
JobWithHooks.make_it_dont_perform do
|
146
138
|
Resque.run!
|
147
139
|
assert(JobWithHooks.markers[:before], 'no before marker set')
|
@@ -152,83 +144,83 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
152
144
|
end
|
153
145
|
end
|
154
146
|
|
155
|
-
|
156
|
-
|
147
|
+
describe "but without before" do
|
148
|
+
before do
|
157
149
|
JobWithHooksWithoutBefore.clear_markers
|
158
150
|
Resque.enqueue(JobWithHooksWithoutBefore)
|
159
151
|
end
|
160
152
|
|
161
|
-
|
153
|
+
it "does not run before hooks during a run" do
|
162
154
|
Resque.run!
|
163
155
|
assert(!JobWithHooksWithoutBefore.markers[:before], 'before marker set, and it should not')
|
164
156
|
end
|
165
157
|
end
|
166
158
|
|
167
|
-
|
168
|
-
|
159
|
+
describe "when before_enqueue returns false" do
|
160
|
+
before do
|
169
161
|
JobWithHooksBeforeBlocks.clear_markers
|
170
162
|
end
|
171
163
|
|
172
|
-
|
164
|
+
it "does not queue" do
|
173
165
|
Resque.enqueue JobWithHooksBeforeBlocks
|
174
166
|
assert_not_queued JobWithHooksBeforeBlocks
|
175
167
|
end
|
176
168
|
|
177
169
|
end
|
178
170
|
|
179
|
-
|
180
|
-
|
171
|
+
describe "but without around" do
|
172
|
+
before do
|
181
173
|
JobWithHooksWithoutAround.clear_markers
|
182
174
|
Resque.enqueue(JobWithHooksWithoutAround)
|
183
175
|
end
|
184
176
|
|
185
|
-
|
177
|
+
it "does not run around hooks during a run" do
|
186
178
|
Resque.run!
|
187
179
|
assert(!JobWithHooksWithoutAround.markers[:around], 'around marker set, and it should not')
|
188
180
|
end
|
189
181
|
end
|
190
182
|
end
|
191
183
|
|
192
|
-
|
193
|
-
|
184
|
+
describe "Block assertions" do
|
185
|
+
it "passes the assert_queued(job) assertion when queued in block" do
|
194
186
|
assert_queues(HighPriorityJob) do
|
195
187
|
Resque.enqueue(HighPriorityJob)
|
196
188
|
end
|
197
189
|
end
|
198
190
|
|
199
|
-
|
191
|
+
it "passes the assert_queued(job) assertion when queued in block and outside" do
|
200
192
|
Resque.enqueue(HighPriorityJob)
|
201
193
|
assert_queues(HighPriorityJob) do
|
202
194
|
Resque.enqueue(HighPriorityJob)
|
203
195
|
end
|
204
196
|
end
|
205
197
|
|
206
|
-
|
198
|
+
it "fails the assert_queued(job) assertion when not queued in block but outside" do
|
207
199
|
Resque.enqueue(LowPriorityJob)
|
208
|
-
|
200
|
+
assert_raises Minitest::Assertion do
|
209
201
|
assert_queues(LowPriorityJob) do
|
210
202
|
# Nothing.
|
211
203
|
end
|
212
204
|
end
|
213
205
|
end
|
214
206
|
|
215
|
-
|
207
|
+
it "passes the assert_not_queued(job) assertion when not queued in block" do
|
216
208
|
Resque.enqueue(LowPriorityJob)
|
217
209
|
assert_not_queued(LowPriorityJob) do
|
218
210
|
# Nothing.
|
219
211
|
end
|
220
212
|
end
|
221
213
|
|
222
|
-
|
223
|
-
|
214
|
+
it "fails the assert_not_queued(job) assertion when not queued in block" do
|
215
|
+
assert_raises Minitest::Assertion do
|
224
216
|
assert_not_queued(LowPriorityJob) do
|
225
217
|
Resque.enqueue(LowPriorityJob)
|
226
218
|
end
|
227
219
|
end
|
228
220
|
end
|
229
221
|
|
230
|
-
|
231
|
-
|
222
|
+
it "fails the assert_not_queued(job) assertion when queued and not in block" do
|
223
|
+
assert_raises Minitest::Assertion do
|
232
224
|
Resque.enqueue(LowPriorityJob)
|
233
225
|
assert_not_queued(LowPriorityJob) do
|
234
226
|
Resque.enqueue(LowPriorityJob)
|
@@ -236,15 +228,15 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
236
228
|
end
|
237
229
|
end
|
238
230
|
|
239
|
-
|
231
|
+
it "passes the assert_nothing_queued assertion when nothing queued in block" do
|
240
232
|
Resque.enqueue(LowPriorityJob)
|
241
233
|
assert_nothing_queued do
|
242
234
|
# Nothing.
|
243
235
|
end
|
244
236
|
end
|
245
237
|
|
246
|
-
|
247
|
-
|
238
|
+
it "fails the assert_nothing_queued assertion when queued in block" do
|
239
|
+
assert_raises Minitest::Assertion do
|
248
240
|
assert_nothing_queued do
|
249
241
|
Resque.enqueue(LowPriorityJob)
|
250
242
|
end
|
@@ -252,127 +244,127 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
252
244
|
end
|
253
245
|
end
|
254
246
|
|
255
|
-
|
256
|
-
|
247
|
+
describe "An empty queue" do
|
248
|
+
it "passes the assert_not_queued(job) assertion" do
|
257
249
|
assert_not_queued(LowPriorityJob)
|
258
250
|
end
|
259
251
|
|
260
|
-
|
261
|
-
|
252
|
+
it "fails the assert_queued(job) assertion" do
|
253
|
+
assert_raises Minitest::Assertion do
|
262
254
|
assert_queued(LowPriorityJob)
|
263
255
|
end
|
264
256
|
end
|
265
257
|
|
266
|
-
|
258
|
+
it "is size 0 when empty" do
|
267
259
|
assert_equal 0, Resque.size(:low)
|
268
260
|
end
|
269
261
|
end
|
270
262
|
|
271
|
-
|
272
|
-
|
263
|
+
describe "A task that schedules a resque job with arguments" do
|
264
|
+
before do
|
273
265
|
Resque.enqueue(JobWithArguments, 1, :test, {:symbol => :symbol})
|
274
266
|
end
|
275
267
|
|
276
|
-
|
268
|
+
it "passes the assert_queued(job, *args) assertion if the args match and sees enqueued symbols as strings" do
|
277
269
|
assert_queued(JobWithArguments, [1, "test", {"symbol"=>"symbol"}])
|
278
270
|
end
|
279
271
|
|
280
|
-
|
272
|
+
it "passes the assert_queued(job, *args) assertion if the args match using symbols" do
|
281
273
|
assert_queued(JobWithArguments, [1, :test, {:symbol => :symbol}])
|
282
274
|
end
|
283
275
|
|
284
|
-
|
276
|
+
it "passes the assert_queued(job) assertion with no args passed" do
|
285
277
|
assert_queued(JobWithArguments)
|
286
278
|
end
|
287
279
|
|
288
|
-
|
289
|
-
|
280
|
+
it "fails the assert_queued(job) assertion if the args don't match" do
|
281
|
+
assert_raises Minitest::Assertion do
|
290
282
|
assert_queued(JobWithArguments, [2, "test"])
|
291
283
|
end
|
292
284
|
end
|
293
285
|
|
294
|
-
|
286
|
+
it "passes the assert_not_queued(job) assertion if the args don't match" do
|
295
287
|
assert_not_queued(JobWithArguments, [2, "test"])
|
296
288
|
end
|
297
289
|
|
298
|
-
|
299
|
-
|
290
|
+
it "fails the assert_not_queued(job) assertion if the args match" do
|
291
|
+
assert_raises Minitest::Assertion do
|
300
292
|
assert_not_queued(JobWithArguments, [1, "test", {"symbol"=>"symbol"}])
|
301
293
|
end
|
302
294
|
end
|
303
295
|
end
|
304
296
|
|
305
|
-
|
306
|
-
|
297
|
+
describe "A job that schedules a new resque job" do
|
298
|
+
before do
|
307
299
|
Resque.enqueue(JobThatCreatesANewJob)
|
308
300
|
end
|
309
301
|
|
310
|
-
|
302
|
+
it "passes the assert_queued(job) assertion" do
|
311
303
|
assert_queued(JobThatCreatesANewJob)
|
312
304
|
end
|
313
305
|
|
314
|
-
|
315
|
-
|
306
|
+
it "fails the assert_not_queued(job) assertion" do
|
307
|
+
assert_raises Minitest::Assertion do
|
316
308
|
assert_not_queued(JobThatCreatesANewJob)
|
317
309
|
end
|
318
310
|
end
|
319
311
|
|
320
|
-
|
312
|
+
it "passes the assert_not_queued(LowPriorityJob) assertion" do
|
321
313
|
assert_not_queued(LowPriorityJob)
|
322
314
|
end
|
323
315
|
|
324
|
-
|
325
|
-
|
316
|
+
describe ", when Resque.run! is called," do
|
317
|
+
before do
|
326
318
|
Resque.run!
|
327
319
|
end
|
328
320
|
|
329
|
-
|
321
|
+
it "clears the job from the queue" do
|
330
322
|
assert_not_queued(JobThatCreatesANewJob)
|
331
323
|
end
|
332
324
|
|
333
|
-
|
325
|
+
it "adds a LowPriorityJob" do
|
334
326
|
assert_queued(LowPriorityJob)
|
335
327
|
end
|
336
328
|
end
|
337
329
|
|
338
|
-
|
339
|
-
|
340
|
-
assert !LowPriorityJob.run?, "The job should not have
|
330
|
+
describe ", when Resque.full_run!" do
|
331
|
+
before do
|
332
|
+
assert !LowPriorityJob.run?, "The job should not have run yet, did you call 'LowPriorityJob.run = false' in teardowns of other tests?"
|
341
333
|
Resque.full_run!
|
342
334
|
end
|
343
335
|
|
344
|
-
|
336
|
+
after do
|
345
337
|
LowPriorityJob.run = false
|
346
338
|
end
|
347
339
|
|
348
|
-
|
340
|
+
it "clears the jobs from the queue" do
|
349
341
|
assert_not_queued(JobThatCreatesANewJob)
|
350
342
|
assert_not_queued(LowPriorityJob)
|
351
343
|
end
|
352
344
|
|
353
|
-
|
345
|
+
it "runs the new resque jobs" do
|
354
346
|
assert LowPriorityJob.run?, "LowPriorityJob should have been run"
|
355
347
|
end
|
356
348
|
end
|
357
349
|
end
|
358
350
|
|
359
|
-
|
360
|
-
|
351
|
+
describe "A task in a different queue" do
|
352
|
+
before do
|
361
353
|
Resque.enqueue(LowPriorityJob)
|
362
354
|
Resque.enqueue(HighPriorityJob)
|
363
355
|
end
|
364
356
|
|
365
|
-
|
357
|
+
it "adds a LowPriorityJob" do
|
366
358
|
assert_queued(LowPriorityJob)
|
367
359
|
end
|
368
360
|
|
369
|
-
|
361
|
+
it "adds a HighPriorityJob" do
|
370
362
|
assert_queued(HighPriorityJob)
|
371
363
|
end
|
372
364
|
|
373
|
-
|
374
|
-
|
375
|
-
Resque.run_for!(Resque.
|
365
|
+
describe ", when Resque.run_for! is called," do
|
366
|
+
it "runs only tasks in the high priority queue" do
|
367
|
+
Resque.run_for!(Resque.queue_from_class(HighPriorityJob))
|
376
368
|
|
377
369
|
assert_queued(LowPriorityJob)
|
378
370
|
assert_not_queued(HighPriorityJob)
|
@@ -380,80 +372,71 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
380
372
|
end
|
381
373
|
end
|
382
374
|
|
383
|
-
|
384
|
-
|
385
|
-
|
375
|
+
describe "An assertion message" do
|
376
|
+
describe "of assert_queued" do
|
377
|
+
it "includes job class and queue content" do
|
386
378
|
begin
|
387
379
|
assert_not_queued(LowPriorityJob)
|
388
|
-
rescue
|
380
|
+
rescue Minitest::Assertion => error
|
389
381
|
assert_equal "LowPriorityJob should have been queued in low: [].", error.message
|
390
382
|
end
|
391
383
|
end
|
392
384
|
|
393
|
-
|
385
|
+
it "includes job arguments if provided" do
|
394
386
|
begin
|
395
387
|
assert_not_queued(JobWithArguments, [1, "test"])
|
396
|
-
rescue
|
388
|
+
rescue Minitest::Assertion => error
|
397
389
|
assert_equal "JobWithArguments with [1, \"test\"] should have been queued in medium: [].", error.message
|
398
390
|
end
|
399
391
|
end
|
400
392
|
end
|
401
393
|
|
402
|
-
|
403
|
-
|
394
|
+
describe "of assert_not_queued" do
|
395
|
+
it "includes job class and queue content" do
|
404
396
|
begin
|
405
397
|
Resque.enqueue(LowPriorityJob)
|
406
398
|
assert_not_queued(LowPriorityJob)
|
407
|
-
rescue
|
408
|
-
|
399
|
+
rescue Minitest::Assertion => error
|
400
|
+
assert_equal "LowPriorityJob should not have been queued in low.", error.message
|
409
401
|
end
|
410
402
|
end
|
411
403
|
|
412
|
-
|
404
|
+
it "includes job arguments if provided" do
|
413
405
|
begin
|
414
406
|
Resque.enqueue(JobWithArguments, 1, "test")
|
415
407
|
assert_not_queued(JobWithArguments, [1, "test"])
|
416
|
-
rescue
|
408
|
+
rescue Minitest::Assertion => error
|
417
409
|
assert_equal "JobWithArguments with [1, \"test\"] should not have been queued in medium.", error.message
|
418
410
|
end
|
419
411
|
end
|
420
412
|
end
|
421
413
|
|
422
|
-
|
423
|
-
|
414
|
+
describe "of assert_nothing_queued" do
|
415
|
+
it "includes diff" do
|
424
416
|
begin
|
425
417
|
Resque.reset!
|
426
418
|
assert_nothing_queued do
|
427
419
|
Resque.enqueue(LowPriorityJob)
|
428
420
|
end
|
429
|
-
rescue
|
430
|
-
assert_equal "No jobs should have been queued.\
|
421
|
+
rescue Minitest::Assertion => error
|
422
|
+
assert_equal "No jobs should have been queued.\nExpected: 0\n Actual: 1", error.message
|
431
423
|
end
|
432
424
|
end
|
433
425
|
end
|
434
426
|
end
|
435
427
|
|
436
|
-
|
437
|
-
|
438
|
-
|
428
|
+
describe "A job that does not specify a queue" do
|
429
|
+
it "receives Resque::NoQueueError" do
|
430
|
+
assert_raises(Resque::NoQueueError) do
|
439
431
|
Resque.enqueue(JobThatDoesNotSpecifyAQueue)
|
440
432
|
end
|
441
433
|
end
|
442
434
|
end
|
443
435
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
should "queue a job with a dasherized name" do
|
453
|
-
assert_nothing_raised do
|
454
|
-
Resque::Job.create(:my_custom_queue, "low-priority-job", "arg1", "arg2")
|
455
|
-
assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
|
456
|
-
end
|
436
|
+
describe "A job that is created using Resque::Job.create" do
|
437
|
+
it "is queued" do
|
438
|
+
Resque::Job.create(:my_custom_queue, "LowPriorityJob", "arg1", "arg2")
|
439
|
+
assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
|
457
440
|
end
|
458
441
|
end
|
459
442
|
|