resque-loner 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
- context "Multiple plugins with multiple hooks" do
3
+ context 'Multiple plugins with multiple hooks' do
4
4
  include PerformJob
5
5
 
6
6
  module Plugin1
7
7
  def before_perform_record_history1(history)
8
8
  history << :before1
9
9
  end
10
+
10
11
  def after_perform_record_history1(history)
11
12
  history << :after1
12
13
  end
@@ -16,6 +17,7 @@ context "Multiple plugins with multiple hooks" do
16
17
  def before_perform_record_history2(history)
17
18
  history << :before2
18
19
  end
20
+
19
21
  def after_perform_record_history2(history)
20
22
  history << :after2
21
23
  end
@@ -29,14 +31,14 @@ context "Multiple plugins with multiple hooks" do
29
31
  end
30
32
  end
31
33
 
32
- test "hooks of each type are executed in alphabetical order" do
33
- result = perform_job(ManyBeforesJob, history=[])
34
- assert_equal true, result, "perform returned true"
34
+ test 'hooks of each type are executed in alphabetical order' do
35
+ result = perform_job(ManyBeforesJob, history = [])
36
+ assert_equal true, result, 'perform returned true'
35
37
  assert_equal [:before1, :before2, :perform, :after1, :after2], history
36
38
  end
37
39
  end
38
40
 
39
- context "Resque::Plugin ordering before_perform" do
41
+ context 'Resque::Plugin ordering before_perform' do
40
42
  include PerformJob
41
43
 
42
44
  module BeforePerformPlugin
@@ -55,14 +57,14 @@ context "Resque::Plugin ordering before_perform" do
55
57
  end
56
58
  end
57
59
 
58
- test "before_perform hooks are executed in order" do
59
- result = perform_job(JobPluginsTestBeforePerformJob, history=[])
60
- assert_equal true, result, "perform returned true"
60
+ test 'before_perform hooks are executed in order' do
61
+ result = perform_job(JobPluginsTestBeforePerformJob, history = [])
62
+ assert_equal true, result, 'perform returned true'
61
63
  assert_equal [:before_perform, :before_perform1, :perform], history
62
64
  end
63
65
  end
64
66
 
65
- context "Resque::Plugin ordering after_perform" do
67
+ context 'Resque::Plugin ordering after_perform' do
66
68
  include PerformJob
67
69
 
68
70
  module AfterPerformPlugin
@@ -81,14 +83,14 @@ context "Resque::Plugin ordering after_perform" do
81
83
  end
82
84
  end
83
85
 
84
- test "after_perform hooks are executed in order" do
85
- result = perform_job(JobPluginsTestAfterPerformJob, history=[])
86
- assert_equal true, result, "perform returned true"
86
+ test 'after_perform hooks are executed in order' do
87
+ result = perform_job(JobPluginsTestAfterPerformJob, history = [])
88
+ assert_equal true, result, 'perform returned true'
87
89
  assert_equal [:perform, :after_perform, :after_perform1], history
88
90
  end
89
91
  end
90
92
 
91
- context "Resque::Plugin ordering around_perform" do
93
+ context 'Resque::Plugin ordering around_perform' do
92
94
  include PerformJob
93
95
 
94
96
  module AroundPerformPlugin1
@@ -105,9 +107,9 @@ context "Resque::Plugin ordering around_perform" do
105
107
  end
106
108
  end
107
109
 
108
- test "around_perform hooks are executed before the job" do
109
- result = perform_job(AroundPerformJustPerformsJob, history=[])
110
- assert_equal true, result, "perform returned true"
110
+ test 'around_perform hooks are executed before the job' do
111
+ result = perform_job(AroundPerformJustPerformsJob, history = [])
112
+ assert_equal true, result, 'perform returned true'
111
113
  assert_equal [:around_perform_plugin1, :perform], history
112
114
  end
113
115
 
@@ -122,9 +124,9 @@ context "Resque::Plugin ordering around_perform" do
122
124
  end
123
125
  end
124
126
 
125
- test "around_perform hooks are executed in order" do
126
- result = perform_job(JobPluginsTestAroundPerformJob, history=[])
127
- assert_equal true, result, "perform returned true"
127
+ test 'around_perform hooks are executed in order' do
128
+ result = perform_job(JobPluginsTestAroundPerformJob, history = [])
129
+ assert_equal true, result, 'perform returned true'
128
130
  assert_equal [:around_perform, :around_perform_plugin1, :perform], history
129
131
  end
130
132
 
@@ -147,9 +149,9 @@ context "Resque::Plugin ordering around_perform" do
147
149
  end
148
150
  end
149
151
 
150
- test "many around_perform are executed in order" do
151
- result = perform_job(AroundPerformJob2, history=[])
152
- assert_equal true, result, "perform returned true"
152
+ test 'many around_perform are executed in order' do
153
+ result = perform_job(AroundPerformJob2, history = [])
154
+ assert_equal true, result, 'perform returned true'
153
155
  assert_equal [:around_perform, :around_perform_plugin1, :around_perform_plugin2, :perform], history
154
156
  end
155
157
 
@@ -172,9 +174,9 @@ context "Resque::Plugin ordering around_perform" do
172
174
  end
173
175
  end
174
176
 
175
- test "the job is aborted if an around_perform hook does not yield" do
176
- result = perform_job(AroundPerformJob3, history=[])
177
- assert_equal false, result, "perform returned false"
177
+ test 'the job is aborted if an around_perform hook does not yield' do
178
+ result = perform_job(AroundPerformJob3, history = [])
179
+ assert_equal false, result, 'perform returned false'
178
180
  assert_equal [:around_perform, :around_perform0], history
179
181
  end
180
182
 
@@ -193,14 +195,14 @@ context "Resque::Plugin ordering around_perform" do
193
195
  extend AroundPerformGetsJobResult
194
196
  end
195
197
 
196
- test "the job is aborted if an around_perform hook does not yield" do
198
+ test 'the job is aborted if an around_perform hook does not yield' do
197
199
  result = perform_job(AroundPerformJobWithReturnValue, 'Bob')
198
- assert_equal true, result, "perform returned true"
200
+ assert_equal true, result, 'perform returned true'
199
201
  assert_equal 'Good job, Bob', AroundPerformJobWithReturnValue.last_job_result
200
202
  end
201
203
  end
202
204
 
203
- context "Resque::Plugin ordering on_failure" do
205
+ context 'Resque::Plugin ordering on_failure' do
204
206
  include PerformJob
205
207
 
206
208
  module OnFailurePlugin
@@ -213,18 +215,18 @@ context "Resque::Plugin ordering on_failure" do
213
215
  extend OnFailurePlugin
214
216
  def self.perform(history)
215
217
  history << :perform
216
- raise StandardError, "oh no"
218
+ fail StandardError, 'oh no'
217
219
  end
218
220
  def self.on_failure(exception, history)
219
221
  history << exception.message
220
222
  end
221
223
  end
222
224
 
223
- test "on_failure hooks are executed in order" do
225
+ test 'on_failure hooks are executed in order' do
224
226
  history = []
225
227
  assert_raises StandardError do
226
228
  perform_job(FailureJob, history)
227
229
  end
228
- assert_equal [:perform, "oh no", "oh no plugin"], history
230
+ assert_equal [:perform, 'oh no', 'oh no plugin'], history
229
231
  end
230
232
  end
@@ -1,41 +1,53 @@
1
1
  require 'test_helper'
2
2
 
3
- context "Resque::Plugin finding hooks" do
3
+ context 'Resque::Plugin finding hooks' do
4
4
  module SimplePlugin
5
5
  extend self
6
6
  def before_perform1; end
7
+
7
8
  def before_perform; end
9
+
8
10
  def before_perform2; end
11
+
9
12
  def after_perform1; end
13
+
10
14
  def after_perform; end
15
+
11
16
  def after_perform2; end
17
+
12
18
  def perform; end
19
+
13
20
  def around_perform1; end
21
+
14
22
  def around_perform; end
23
+
15
24
  def around_perform2; end
25
+
16
26
  def on_failure1; end
27
+
17
28
  def on_failure; end
29
+
18
30
  def on_failure2; end
19
31
  end
20
32
 
21
- test "before_perform hooks are found and sorted" do
22
- assert_equal ["before_perform", "before_perform1", "before_perform2"], Resque::Plugin.before_hooks(SimplePlugin).map {|m| m.to_s}
33
+ test 'before_perform hooks are found and sorted' do
34
+ assert_equal %w(before_perform before_perform1 before_perform2), Resque::Plugin.before_hooks(SimplePlugin).map { |m| m.to_s }
23
35
  end
24
36
 
25
- test "after_perform hooks are found and sorted" do
26
- assert_equal ["after_perform", "after_perform1", "after_perform2"], Resque::Plugin.after_hooks(SimplePlugin).map {|m| m.to_s}
37
+ test 'after_perform hooks are found and sorted' do
38
+ assert_equal %w(after_perform after_perform1 after_perform2), Resque::Plugin.after_hooks(SimplePlugin).map { |m| m.to_s }
27
39
  end
28
40
 
29
- test "around_perform hooks are found and sorted" do
30
- assert_equal ["around_perform", "around_perform1", "around_perform2"], Resque::Plugin.around_hooks(SimplePlugin).map {|m| m.to_s}
41
+ test 'around_perform hooks are found and sorted' do
42
+ assert_equal %w(around_perform around_perform1 around_perform2), Resque::Plugin.around_hooks(SimplePlugin).map { |m| m.to_s }
31
43
  end
32
44
 
33
- test "on_failure hooks are found and sorted" do
34
- assert_equal ["on_failure", "on_failure1", "on_failure2"], Resque::Plugin.failure_hooks(SimplePlugin).map {|m| m.to_s}
45
+ test 'on_failure hooks are found and sorted' do
46
+ assert_equal %w(on_failure on_failure1 on_failure2), Resque::Plugin.failure_hooks(SimplePlugin).map { |m| m.to_s }
35
47
  end
36
48
  end
37
49
 
38
- context "Resque::Plugin linting" do
50
+ context 'Resque::Plugin linting' do
39
51
  module ::BadBefore
40
52
  def self.before_perform; end
41
53
  end
@@ -49,39 +61,39 @@ context "Resque::Plugin linting" do
49
61
  def self.on_failure; end
50
62
  end
51
63
 
52
- test "before_perform must be namespaced" do
64
+ test 'before_perform must be namespaced' do
53
65
  begin
54
66
  Resque::Plugin.lint(BadBefore)
55
- assert false, "should have failed"
67
+ assert false, 'should have failed'
56
68
  rescue Resque::Plugin::LintError => e
57
- assert_equal "BadBefore.before_perform is not namespaced", e.message
69
+ assert_equal 'BadBefore.before_perform is not namespaced', e.message
58
70
  end
59
71
  end
60
72
 
61
- test "after_perform must be namespaced" do
73
+ test 'after_perform must be namespaced' do
62
74
  begin
63
75
  Resque::Plugin.lint(BadAfter)
64
- assert false, "should have failed"
76
+ assert false, 'should have failed'
65
77
  rescue Resque::Plugin::LintError => e
66
- assert_equal "BadAfter.after_perform is not namespaced", e.message
78
+ assert_equal 'BadAfter.after_perform is not namespaced', e.message
67
79
  end
68
80
  end
69
81
 
70
- test "around_perform must be namespaced" do
82
+ test 'around_perform must be namespaced' do
71
83
  begin
72
84
  Resque::Plugin.lint(BadAround)
73
- assert false, "should have failed"
85
+ assert false, 'should have failed'
74
86
  rescue Resque::Plugin::LintError => e
75
- assert_equal "BadAround.around_perform is not namespaced", e.message
87
+ assert_equal 'BadAround.around_perform is not namespaced', e.message
76
88
  end
77
89
  end
78
90
 
79
- test "on_failure must be namespaced" do
91
+ test 'on_failure must be namespaced' do
80
92
  begin
81
93
  Resque::Plugin.lint(BadFailure)
82
- assert false, "should have failed"
94
+ assert false, 'should have failed'
83
95
  rescue Resque::Plugin::LintError => e
84
- assert_equal "BadFailure.on_failure is not namespaced", e.message
96
+ assert_equal 'BadFailure.on_failure is not namespaced', e.message
85
97
  end
86
98
  end
87
99
 
@@ -98,19 +110,19 @@ context "Resque::Plugin linting" do
98
110
  def self.on_failure1; end
99
111
  end
100
112
 
101
- test "before_perform1 is an ok name" do
113
+ test 'before_perform1 is an ok name' do
102
114
  Resque::Plugin.lint(GoodBefore)
103
115
  end
104
116
 
105
- test "after_perform1 is an ok name" do
117
+ test 'after_perform1 is an ok name' do
106
118
  Resque::Plugin.lint(GoodAfter)
107
119
  end
108
120
 
109
- test "around_perform1 is an ok name" do
121
+ test 'around_perform1 is an ok name' do
110
122
  Resque::Plugin.lint(GoodAround)
111
123
  end
112
124
 
113
- test "on_failure1 is an ok name" do
125
+ test 'on_failure1 is an ok name' do
114
126
  Resque::Plugin.lint(GoodFailure)
115
127
  end
116
128
  end
@@ -6,10 +6,10 @@ daemonize yes
6
6
 
7
7
  # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
8
  # You can specify a custom pid file location here.
9
- pidfile ./spec/redis-test.pid
9
+ pidfile ./test/redis-test-cluster.pid
10
10
 
11
11
  # Accept connections on the specified port, default is 6379
12
- port 9736
12
+ port 9737
13
13
 
14
14
  # If you want you can bind a single interface, if the bind option is not
15
15
  # specified all the interfaces will listen for connections.
@@ -35,11 +35,11 @@ save 300 10
35
35
  save 60 10000
36
36
 
37
37
  # The filename where to dump the DB
38
- dbfilename dump.rdb
38
+ dbfilename dump-cluster.rdb
39
39
 
40
40
  # For default save/load DB in/from the working directory
41
41
  # Note that you must specify a directory not a file name.
42
- dir ./spec/
42
+ dir ./test/
43
43
 
44
44
  # Set server verbosity to 'debug'
45
45
  # it can be one of:
@@ -1,18 +1,18 @@
1
1
  require 'test_helper'
2
2
  require 'resque/server/test_helper'
3
-
3
+
4
4
  # Root path test
5
- context "on GET to /" do
6
- setup { get "/" }
5
+ context 'on GET to /' do
6
+ setup { get '/' }
7
7
 
8
- test "redirect to overview" do
8
+ test 'redirect to overview' do
9
9
  follow_redirect!
10
10
  end
11
11
  end
12
12
 
13
13
  # Global overview
14
- context "on GET to /overview" do
15
- setup { get "/overview" }
14
+ context 'on GET to /overview' do
15
+ setup { get '/overview' }
16
16
 
17
17
  test "should at least display 'queues'" do
18
18
  assert last_response.body.include?('Queues')
@@ -20,34 +20,40 @@ context "on GET to /overview" do
20
20
  end
21
21
 
22
22
  # Working jobs
23
- context "on GET to /working" do
24
- setup { get "/working" }
23
+ context 'on GET to /working' do
24
+ setup { get '/working' }
25
25
 
26
26
  should_respond_with_success
27
27
  end
28
28
 
29
29
  # Failed
30
- context "on GET to /failed" do
31
- setup { get "/failed" }
30
+ context 'on GET to /failed' do
31
+ setup { get '/failed' }
32
+
33
+ should_respond_with_success
34
+ end
35
+
36
+ # Stats
37
+ context 'on GET to /stats/resque' do
38
+ setup { get '/stats/resque' }
32
39
 
33
40
  should_respond_with_success
34
41
  end
35
42
 
36
- # Stats
37
- context "on GET to /stats/resque" do
38
- setup { get "/stats/resque" }
43
+ context 'on GET to /stats/redis' do
44
+ setup { get '/stats/redis' }
39
45
 
40
46
  should_respond_with_success
41
47
  end
42
48
 
43
- context "on GET to /stats/redis" do
44
- setup { get "/stats/redis" }
49
+ context 'on GET to /stats/resque' do
50
+ setup { get '/stats/keys' }
45
51
 
46
52
  should_respond_with_success
47
53
  end
48
54
 
49
- context "on GET to /stats/resque" do
50
- setup { get "/stats/keys" }
55
+ context 'also works with slash at the end' do
56
+ setup { get '/working/' }
51
57
 
52
58
  should_respond_with_success
53
59
  end
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+ require 'resque/failure/redis'
3
+
4
+ context 'Resque::Failure::Redis' do
5
+ setup do
6
+ @bad_string = [39, 250, 141, 168, 138, 191, 52, 211, 159, 86, 93, 95, 39].map { |c| c.chr }.join
7
+ exception = StandardError.exception(@bad_string)
8
+ worker = Resque::Worker.new(:test)
9
+ queue = 'queue'
10
+ payload = { 'class' => Object, 'args' => 3 }
11
+ @redis_backend = Resque::Failure::Redis.new(exception, worker, queue, payload)
12
+ end
13
+
14
+ test 'cleans up bad strings before saving the failure, in order to prevent errors on the resque UI' do
15
+ # test assumption: the bad string should not be able to round trip though JSON
16
+ assert_raises(MultiJson::DecodeError) do
17
+ MultiJson.decode(MultiJson.encode(@bad_string))
18
+ end
19
+
20
+ @redis_backend.save
21
+ Resque::Failure::Redis.all # should not raise an error
22
+ end
23
+ end
@@ -1,36 +1,41 @@
1
1
  require 'test_helper'
2
2
 
3
- context "Resque" do
3
+ context 'Resque' do
4
4
  setup do
5
5
  Resque.redis.flushall
6
6
 
7
- Resque.push(:people, { 'name' => 'chris' })
8
- Resque.push(:people, { 'name' => 'bob' })
9
- Resque.push(:people, { 'name' => 'mark' })
7
+ Resque.push(:people, 'name' => 'chris')
8
+ Resque.push(:people, 'name' => 'bob')
9
+ Resque.push(:people, 'name' => 'mark')
10
+ @original_redis = Resque.redis
10
11
  end
11
12
 
12
- test "can set a namespace through a url-like string" do
13
+ teardown do
14
+ Resque.redis = @original_redis
15
+ end
16
+
17
+ test 'can set a namespace through a url-like string' do
13
18
  assert Resque.redis
14
19
  assert_equal :resque, Resque.redis.namespace
15
20
  Resque.redis = 'localhost:9736/namespace'
16
21
  assert_equal 'namespace', Resque.redis.namespace
17
22
  end
18
23
 
19
- test "redis= works correctly with a Redis::Namespace param" do
20
- new_redis = Redis.new(:host => "localhost", :port => 9736)
21
- new_namespace = Redis::Namespace.new("namespace", :redis => new_redis)
24
+ test 'redis= works correctly with a Redis::Namespace param' do
25
+ new_redis = Redis.new(host: 'localhost', port: 9736)
26
+ new_namespace = Redis::Namespace.new('namespace', redis: new_redis)
22
27
  Resque.redis = new_namespace
23
28
  assert_equal new_namespace, Resque.redis
24
29
 
25
30
  Resque.redis = 'localhost:9736/namespace'
26
31
  end
27
32
 
28
- test "can put jobs on a queue" do
33
+ test 'can put jobs on a queue' do
29
34
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
30
35
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
31
36
  end
32
37
 
33
- test "can grab jobs off a queue" do
38
+ test 'can grab jobs off a queue' do
34
39
  Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
35
40
 
36
41
  job = Resque.reserve(:jobs)
@@ -41,7 +46,7 @@ context "Resque" do
41
46
  assert_equal '/tmp', job.args[1]
42
47
  end
43
48
 
44
- test "can re-queue jobs" do
49
+ test 'can re-queue jobs' do
45
50
  Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
46
51
 
47
52
  job = Resque.reserve(:jobs)
@@ -50,7 +55,7 @@ context "Resque" do
50
55
  assert_equal job, Resque.reserve(:jobs)
51
56
  end
52
57
 
53
- test "can put jobs on a queue by way of an ivar" do
58
+ test 'can put jobs on a queue by way of an ivar' do
54
59
  assert_equal 0, Resque.size(:ivar)
55
60
  assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
56
61
  assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
@@ -66,7 +71,7 @@ context "Resque" do
66
71
  assert_equal nil, Resque.reserve(:ivar)
67
72
  end
68
73
 
69
- test "can remove jobs from a queue by way of an ivar" do
74
+ test 'can remove jobs from a queue by way of an ivar' do
70
75
  assert_equal 0, Resque.size(:ivar)
71
76
  assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
72
77
  assert Resque.enqueue(SomeIvarJob, 30, '/tmp')
@@ -81,13 +86,13 @@ context "Resque" do
81
86
  assert_equal 1, Resque.size(:ivar)
82
87
  end
83
88
 
84
- test "jobs have a nice #inspect" do
89
+ test 'jobs have a nice #inspect' do
85
90
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
86
91
  job = Resque.reserve(:jobs)
87
92
  assert_equal '(Job{jobs} | SomeJob | [20, "/tmp"])', job.inspect
88
93
  end
89
94
 
90
- test "jobs can be destroyed" do
95
+ test 'jobs can be destroyed' do
91
96
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
92
97
  assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
93
98
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
@@ -101,7 +106,7 @@ context "Resque" do
101
106
  assert_equal 2, Resque.size(:jobs)
102
107
  end
103
108
 
104
- test "jobs can test for equality" do
109
+ test 'jobs can test for equality' do
105
110
  assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
106
111
  assert Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
107
112
  assert_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
@@ -115,7 +120,7 @@ context "Resque" do
115
120
  assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
116
121
  end
117
122
 
118
- test "can put jobs on a queue by way of a method" do
123
+ test 'can put jobs on a queue by way of a method' do
119
124
  assert_equal 0, Resque.size(:method)
120
125
  assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
121
126
  assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
@@ -131,30 +136,40 @@ context "Resque" do
131
136
  assert_equal nil, Resque.reserve(:method)
132
137
  end
133
138
 
134
- test "needs to infer a queue with enqueue" do
139
+ test 'can define a queue for jobs by way of a method' do
140
+ assert_equal 0, Resque.size(:method)
141
+ assert Resque.enqueue_to(:new_queue, SomeMethodJob, 20, '/tmp')
142
+
143
+ job = Resque.reserve(:new_queue)
144
+ assert_equal SomeMethodJob, job.payload_class
145
+ assert_equal 20, job.args[0]
146
+ assert_equal '/tmp', job.args[1]
147
+ end
148
+
149
+ test 'needs to infer a queue with enqueue' do
135
150
  assert_raises Resque::NoQueueError do
136
151
  Resque.enqueue(SomeJob, 20, '/tmp')
137
152
  end
138
153
  end
139
154
 
140
- test "validates job for queue presence" do
155
+ test 'validates job for queue presence' do
141
156
  assert_raises Resque::NoQueueError do
142
157
  Resque.validate(SomeJob)
143
158
  end
144
159
  end
145
160
 
146
- test "can put items on a queue" do
147
- assert Resque.push(:people, { 'name' => 'jon' })
161
+ test 'can put items on a queue' do
162
+ assert Resque.push(:people, 'name' => 'jon')
148
163
  end
149
164
 
150
- test "can pull items off a queue" do
165
+ test 'can pull items off a queue' do
151
166
  assert_equal({ 'name' => 'chris' }, Resque.pop(:people))
152
167
  assert_equal({ 'name' => 'bob' }, Resque.pop(:people))
153
168
  assert_equal({ 'name' => 'mark' }, Resque.pop(:people))
154
169
  assert_equal nil, Resque.pop(:people)
155
170
  end
156
171
 
157
- test "knows how big a queue is" do
172
+ test 'knows how big a queue is' do
158
173
  assert_equal 3, Resque.size(:people)
159
174
 
160
175
  assert_equal({ 'name' => 'chris' }, Resque.pop(:people))
@@ -165,12 +180,12 @@ context "Resque" do
165
180
  assert_equal 0, Resque.size(:people)
166
181
  end
167
182
 
168
- test "can peek at a queue" do
183
+ test 'can peek at a queue' do
169
184
  assert_equal({ 'name' => 'chris' }, Resque.peek(:people))
170
185
  assert_equal 3, Resque.size(:people)
171
186
  end
172
187
 
173
- test "can peek multiple items on a queue" do
188
+ test 'can peek multiple items on a queue' do
174
189
  assert_equal({ 'name' => 'bob' }, Resque.peek(:people, 1, 1))
175
190
 
176
191
  assert_equal([{ 'name' => 'bob' }, { 'name' => 'mark' }], Resque.peek(:people, 1, 2))
@@ -181,36 +196,36 @@ context "Resque" do
181
196
  assert_equal [], Resque.peek(:people, 3, 2)
182
197
  end
183
198
 
184
- test "knows what queues it is managing" do
199
+ test 'knows what queues it is managing' do
185
200
  assert_equal %w( people ), Resque.queues
186
- Resque.push(:cars, { 'make' => 'bmw' })
201
+ Resque.push(:cars, 'make' => 'bmw')
187
202
  assert_equal %w( cars people ), Resque.queues
188
203
  end
189
204
 
190
- test "queues are always a list" do
205
+ test 'queues are always a list' do
191
206
  Resque.redis.flushall
192
207
  assert_equal [], Resque.queues
193
208
  end
194
209
 
195
- test "can delete a queue" do
196
- Resque.push(:cars, { 'make' => 'bmw' })
210
+ test 'can delete a queue' do
211
+ Resque.push(:cars, 'make' => 'bmw')
197
212
  assert_equal %w( cars people ), Resque.queues
198
213
  Resque.remove_queue(:people)
199
214
  assert_equal %w( cars ), Resque.queues
200
215
  assert_equal nil, Resque.pop(:people)
201
216
  end
202
217
 
203
- test "keeps track of resque keys" do
204
- assert_equal ["queue:people", "queues"], Resque.keys
218
+ test 'keeps track of resque keys' do
219
+ assert_equal ['queue:people', 'queues'].sort, Resque.keys.sort
205
220
  end
206
221
 
207
- test "badly wants a class name, too" do
222
+ test 'badly wants a class name, too' do
208
223
  assert_raises Resque::NoClassError do
209
224
  Resque::Job.create(:jobs, nil)
210
225
  end
211
226
  end
212
227
 
213
- test "keeps stats" do
228
+ test 'keeps stats' do
214
229
  Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
215
230
  Resque::Job.create(:jobs, BadJob)
216
231
  Resque::Job.create(:jobs, GoodJob)
@@ -238,16 +253,20 @@ context "Resque" do
238
253
  assert_equal 3, stats[:queues]
239
254
  assert_equal 3, stats[:processed]
240
255
  assert_equal 1, stats[:failed]
241
- assert_equal [Resque.redis.respond_to?(:server) ? 'localhost:9736' : 'redis://localhost:9736/0'], stats[:servers]
256
+ if ENV.key? 'RESQUE_DISTRIBUTED'
257
+ assert_equal [Resque.redis.respond_to?(:server) ? 'localhost:9736, localhost:9737' : 'redis://localhost:9736/0, redis://localhost:9737/0'], stats[:servers]
258
+ else
259
+ assert_equal [Resque.redis.respond_to?(:server) ? 'localhost:9736' : 'redis://localhost:9736/0'], stats[:servers]
260
+ end
242
261
  end
243
262
 
244
- test "decode bad json" do
263
+ test 'decode bad json' do
245
264
  assert_raises Resque::Helpers::DecodeException do
246
265
  Resque.decode("{\"error\":\"Module not found \\u002\"}")
247
266
  end
248
267
  end
249
268
 
250
- test "inlining jobs" do
269
+ test 'inlining jobs' do
251
270
  begin
252
271
  Resque.inline = true
253
272
  Resque.enqueue(SomeIvarJob, 20, '/tmp')