nfo-resque-mongo 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/HISTORY.md +259 -0
  2. data/LICENSE +20 -0
  3. data/README.markdown +828 -0
  4. data/Rakefile +73 -0
  5. data/bin/resque +75 -0
  6. data/bin/resque-web +23 -0
  7. data/lib/resque/errors.rb +10 -0
  8. data/lib/resque/failure/base.rb +74 -0
  9. data/lib/resque/failure/hoptoad.rb +139 -0
  10. data/lib/resque/failure/mongo.rb +92 -0
  11. data/lib/resque/failure/multiple.rb +60 -0
  12. data/lib/resque/failure.rb +82 -0
  13. data/lib/resque/helpers.rb +79 -0
  14. data/lib/resque/job.rb +228 -0
  15. data/lib/resque/plugin.rb +51 -0
  16. data/lib/resque/queue_stats.rb +58 -0
  17. data/lib/resque/server/public/idle.png +0 -0
  18. data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
  19. data/lib/resque/server/public/jquery.relatize_date.js +95 -0
  20. data/lib/resque/server/public/poll.png +0 -0
  21. data/lib/resque/server/public/ranger.js +73 -0
  22. data/lib/resque/server/public/reset.css +48 -0
  23. data/lib/resque/server/public/style.css +86 -0
  24. data/lib/resque/server/public/working.png +0 -0
  25. data/lib/resque/server/test_helper.rb +19 -0
  26. data/lib/resque/server/views/error.erb +1 -0
  27. data/lib/resque/server/views/failed.erb +75 -0
  28. data/lib/resque/server/views/key_sets.erb +19 -0
  29. data/lib/resque/server/views/key_string.erb +11 -0
  30. data/lib/resque/server/views/layout.erb +38 -0
  31. data/lib/resque/server/views/next_more.erb +19 -0
  32. data/lib/resque/server/views/overview.erb +4 -0
  33. data/lib/resque/server/views/queues.erb +49 -0
  34. data/lib/resque/server/views/stats.erb +62 -0
  35. data/lib/resque/server/views/workers.erb +109 -0
  36. data/lib/resque/server/views/working.erb +68 -0
  37. data/lib/resque/server.rb +222 -0
  38. data/lib/resque/stat.rb +55 -0
  39. data/lib/resque/tasks.rb +42 -0
  40. data/lib/resque/version.rb +3 -0
  41. data/lib/resque/worker.rb +524 -0
  42. data/lib/resque.rb +384 -0
  43. data/tasks/redis.rake +161 -0
  44. data/tasks/resque.rake +2 -0
  45. data/test/dump.rdb +0 -0
  46. data/test/job_hooks_test.rb +323 -0
  47. data/test/job_plugins_test.rb +230 -0
  48. data/test/plugin_test.rb +116 -0
  49. data/test/queue_stats_test.rb +57 -0
  50. data/test/redis-test.conf +115 -0
  51. data/test/resque-web_test.rb +48 -0
  52. data/test/resque_test.rb +256 -0
  53. data/test/test_helper.rb +151 -0
  54. data/test/worker_test.rb +356 -0
  55. metadata +166 -0
@@ -0,0 +1,116 @@
1
+ require 'test_helper'
2
+
3
+ context "Resque::Plugin finding hooks" do
4
+ module SimplePlugin
5
+ extend self
6
+ def before_perform1; end
7
+ def before_perform; end
8
+ def before_perform2; end
9
+ def after_perform1; end
10
+ def after_perform; end
11
+ def after_perform2; end
12
+ def perform; end
13
+ def around_perform1; end
14
+ def around_perform; end
15
+ def around_perform2; end
16
+ def on_failure1; end
17
+ def on_failure; end
18
+ def on_failure2; end
19
+ end
20
+
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}
23
+ end
24
+
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}
27
+ end
28
+
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}
31
+ end
32
+
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}
35
+ end
36
+ end
37
+
38
+ context "Resque::Plugin linting" do
39
+ module ::BadBefore
40
+ def self.before_perform; end
41
+ end
42
+ module ::BadAfter
43
+ def self.after_perform; end
44
+ end
45
+ module ::BadAround
46
+ def self.around_perform; end
47
+ end
48
+ module ::BadFailure
49
+ def self.on_failure; end
50
+ end
51
+
52
+ test "before_perform must be namespaced" do
53
+ begin
54
+ Resque::Plugin.lint(BadBefore)
55
+ assert false, "should have failed"
56
+ rescue Resque::Plugin::LintError => e
57
+ assert_equal "BadBefore.before_perform is not namespaced", e.message
58
+ end
59
+ end
60
+
61
+ test "after_perform must be namespaced" do
62
+ begin
63
+ Resque::Plugin.lint(BadAfter)
64
+ assert false, "should have failed"
65
+ rescue Resque::Plugin::LintError => e
66
+ assert_equal "BadAfter.after_perform is not namespaced", e.message
67
+ end
68
+ end
69
+
70
+ test "around_perform must be namespaced" do
71
+ begin
72
+ Resque::Plugin.lint(BadAround)
73
+ assert false, "should have failed"
74
+ rescue Resque::Plugin::LintError => e
75
+ assert_equal "BadAround.around_perform is not namespaced", e.message
76
+ end
77
+ end
78
+
79
+ test "on_failure must be namespaced" do
80
+ begin
81
+ Resque::Plugin.lint(BadFailure)
82
+ assert false, "should have failed"
83
+ rescue Resque::Plugin::LintError => e
84
+ assert_equal "BadFailure.on_failure is not namespaced", e.message
85
+ end
86
+ end
87
+
88
+ module GoodBefore
89
+ def self.before_perform1; end
90
+ end
91
+ module GoodAfter
92
+ def self.after_perform1; end
93
+ end
94
+ module GoodAround
95
+ def self.around_perform1; end
96
+ end
97
+ module GoodFailure
98
+ def self.on_failure1; end
99
+ end
100
+
101
+ test "before_perform1 is an ok name" do
102
+ Resque::Plugin.lint(GoodBefore)
103
+ end
104
+
105
+ test "after_perform1 is an ok name" do
106
+ Resque::Plugin.lint(GoodAfter)
107
+ end
108
+
109
+ test "around_perform1 is an ok name" do
110
+ Resque::Plugin.lint(GoodAround)
111
+ end
112
+
113
+ test "on_failure1 is an ok name" do
114
+ Resque::Plugin.lint(GoodFailure)
115
+ end
116
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + '/test_helper'
2
+
3
+ context "Queue Statistics" do
4
+ setup do
5
+ Resque.flushall
6
+ end
7
+
8
+ test "Creating a queue named 'test' and check it exists in the queues list" do
9
+ queue_stats = Resque::QueueStats.new(:test)
10
+ list = Resque::QueueStats.list
11
+ assert list.include?('test')
12
+ end
13
+
14
+ test "Creating queues and check it can be filtered in the queues list" do
15
+ queue_stats = Resque::QueueStats.new(:abc)
16
+ queue_stats = Resque::QueueStats.new(:abd)
17
+ queue_stats = Resque::QueueStats.new(:xyz)
18
+
19
+ list = Resque::QueueStats.list('ab*')
20
+ assert list.include?('abc')
21
+ assert list.include?('abd')
22
+ assert !list.include?('xyz')
23
+
24
+ list = Resque::QueueStats.list(['x*', 'abc'])
25
+ assert list.include?('abc')
26
+ assert !list.include?('abd')
27
+ assert list.include?('xyz')
28
+ end
29
+
30
+ test "We can add an remove queues" do
31
+ test_1 = Resque::QueueStats.new(:test1)
32
+ list = Resque::QueueStats.list
33
+ assert list.include?('test1')
34
+ Resque::QueueStats.remove(:test1)
35
+ list = Resque::QueueStats.list
36
+ assert !list.include?('test1')
37
+ end
38
+
39
+ test "both add_job, remove_job and work" do
40
+ ## test class methods
41
+ Resque::QueueStats.add_job(:test)
42
+ assert_equal 1,Resque::QueueStats.size(:test)
43
+ Resque::QueueStats.remove_job(:test)
44
+ assert_equal 0,Resque::QueueStats.size(:test)
45
+ end
46
+
47
+
48
+ test "job counter in QueueStats works" do
49
+ assert Resque::Job.create(:stats, 'SomeJob', 20, '/tmp')
50
+ ## same for the class method version
51
+ assert_equal 1,Resque::QueueStats.size(:stats)
52
+ assert Resque::Job.create(:stats, 'SomeJob', 22, '/tmp')
53
+ assert_equal 2,Resque::QueueStats.size(:stats)
54
+ job = Resque.pop(:stats)
55
+ assert_equal 1,Resque::QueueStats.size(:stats)
56
+ end
57
+ end
@@ -0,0 +1,115 @@
1
+ # Redis configuration file example
2
+
3
+ # By default Redis does not run as a daemon. Use 'yes' if you need it.
4
+ # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
5
+ daemonize yes
6
+
7
+ # When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
8
+ # You can specify a custom pid file location here.
9
+ pidfile ./test/redis-test.pid
10
+
11
+ # Accept connections on the specified port, default is 6379
12
+ port 9736
13
+
14
+ # If you want you can bind a single interface, if the bind option is not
15
+ # specified all the interfaces will listen for connections.
16
+ #
17
+ # bind 127.0.0.1
18
+
19
+ # Close the connection after a client is idle for N seconds (0 to disable)
20
+ timeout 300
21
+
22
+ # Save the DB on disk:
23
+ #
24
+ # save <seconds> <changes>
25
+ #
26
+ # Will save the DB if both the given number of seconds and the given
27
+ # number of write operations against the DB occurred.
28
+ #
29
+ # In the example below the behaviour will be to save:
30
+ # after 900 sec (15 min) if at least 1 key changed
31
+ # after 300 sec (5 min) if at least 10 keys changed
32
+ # after 60 sec if at least 10000 keys changed
33
+ save 900 1
34
+ save 300 10
35
+ save 60 10000
36
+
37
+ # The filename where to dump the DB
38
+ dbfilename dump.rdb
39
+
40
+ # For default save/load DB in/from the working directory
41
+ # Note that you must specify a directory not a file name.
42
+ dir ./test/
43
+
44
+ # Set server verbosity to 'debug'
45
+ # it can be one of:
46
+ # debug (a lot of information, useful for development/testing)
47
+ # notice (moderately verbose, what you want in production probably)
48
+ # warning (only very important / critical messages are logged)
49
+ loglevel debug
50
+
51
+ # Specify the log file name. Also 'stdout' can be used to force
52
+ # the demon to log on the standard output. Note that if you use standard
53
+ # output for logging but daemonize, logs will be sent to /dev/null
54
+ logfile stdout
55
+
56
+ # Set the number of databases. The default database is DB 0, you can select
57
+ # a different one on a per-connection basis using SELECT <dbid> where
58
+ # dbid is a number between 0 and 'databases'-1
59
+ databases 16
60
+
61
+ ################################# REPLICATION #################################
62
+
63
+ # Master-Slave replication. Use slaveof to make a Redis instance a copy of
64
+ # another Redis server. Note that the configuration is local to the slave
65
+ # so for example it is possible to configure the slave to save the DB with a
66
+ # different interval, or to listen to another port, and so on.
67
+
68
+ # slaveof <masterip> <masterport>
69
+
70
+ ################################## SECURITY ###################################
71
+
72
+ # Require clients to issue AUTH <PASSWORD> before processing any other
73
+ # commands. This might be useful in environments in which you do not trust
74
+ # others with access to the host running redis-server.
75
+ #
76
+ # This should stay commented out for backward compatibility and because most
77
+ # people do not need auth (e.g. they run their own servers).
78
+
79
+ # requirepass foobared
80
+
81
+ ################################### LIMITS ####################################
82
+
83
+ # Set the max number of connected clients at the same time. By default there
84
+ # is no limit, and it's up to the number of file descriptors the Redis process
85
+ # is able to open. The special value '0' means no limts.
86
+ # Once the limit is reached Redis will close all the new connections sending
87
+ # an error 'max number of clients reached'.
88
+
89
+ # maxclients 128
90
+
91
+ # Don't use more memory than the specified amount of bytes.
92
+ # When the memory limit is reached Redis will try to remove keys with an
93
+ # EXPIRE set. It will try to start freeing keys that are going to expire
94
+ # in little time and preserve keys with a longer time to live.
95
+ # Redis will also try to remove objects from free lists if possible.
96
+ #
97
+ # If all this fails, Redis will start to reply with errors to commands
98
+ # that will use more memory, like SET, LPUSH, and so on, and will continue
99
+ # to reply to most read-only commands like GET.
100
+ #
101
+ # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
102
+ # 'state' server or cache, not as a real DB. When Redis is used as a real
103
+ # database the memory usage will grow over the weeks, it will be obvious if
104
+ # it is going to use too much memory in the long run, and you'll have the time
105
+ # to upgrade. With maxmemory after the limit is reached you'll start to get
106
+ # errors for write operations, and this may even lead to DB inconsistency.
107
+
108
+ # maxmemory <bytes>
109
+
110
+ ############################### ADVANCED CONFIG ###############################
111
+
112
+ # Glue small output buffers together in order to send small replies in a
113
+ # single TCP packet. Uses a bit more CPU but most of the times it is a win
114
+ # in terms of number of queries per second. Use 'yes' if unsure.
115
+ glueoutputbuf yes
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'resque/server/test_helper'
3
+
4
+ # Root path test
5
+ context "on GET to /" do
6
+ setup { get "/" }
7
+
8
+ test "redirect to overview" do
9
+ follow_redirect!
10
+ end
11
+ end
12
+
13
+ # Global overview
14
+ context "on GET to /overview" do
15
+ setup { get "/overview" }
16
+
17
+ test "should at least display 'queues'" do
18
+ assert last_response.body.include?('Queues')
19
+ end
20
+ end
21
+
22
+ # Working jobs
23
+ context "on GET to /working" do
24
+ setup { get "/working" }
25
+
26
+ should_respond_with_success
27
+ end
28
+
29
+ # Failed
30
+ context "on GET to /failed" do
31
+ setup { get "/failed" }
32
+
33
+ should_respond_with_success
34
+ end
35
+
36
+ # Search failed jobs
37
+ context "on GET to /failed with a search query" do
38
+ setup {get "/failed?q=toto"}
39
+
40
+ should_respond_with_success
41
+ end
42
+
43
+ # Stats
44
+ context "on GET to /stats/resque" do
45
+ setup { get "/stats/resque" }
46
+
47
+ should_respond_with_success
48
+ end
@@ -0,0 +1,256 @@
1
+ require 'test_helper'
2
+
3
+ context "Resque" do
4
+ setup do
5
+ Resque.flushall
6
+
7
+ Resque.push(:people, { 'name' => 'chris' })
8
+ Resque.push(:people, { 'name' => 'bob' })
9
+ Resque.push(:people, { 'name' => 'mark' })
10
+ end
11
+
12
+ test "there is a queue named people" do
13
+ #STDERR.puts Resque.queues.inspect
14
+ assert Resque.queues.include? 'people'
15
+ end
16
+
17
+ test "can put jobs on a queue" do
18
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
19
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
20
+ assert_equal 2, Resque.size(:jobs)
21
+ end
22
+
23
+ test "can grab jobs off a queue" do
24
+ Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
25
+ Resque::Job.create(:jobs, 'some-other-job', 20, '/tmp')
26
+
27
+ job = Resque.reserve(:jobs)
28
+
29
+ assert_kind_of Resque::Job, job
30
+ assert_equal SomeJob, job.payload_class
31
+ assert_equal 20, job.args[0]
32
+ assert_equal '/tmp', job.args[1]
33
+ assert_equal 1, Resque.size(:jobs)
34
+ end
35
+
36
+ test "can re-queue jobs" do
37
+ Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
38
+
39
+ job = Resque.reserve(:jobs)
40
+ job.recreate
41
+
42
+ assert_equal job, Resque.reserve(:jobs)
43
+ end
44
+
45
+ test "can put jobs on a queue by way of an ivar" do
46
+ assert_equal 0, Resque.size(:ivar)
47
+ assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
48
+ assert_equal 1, Resque.size(:ivar)
49
+ assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
50
+ assert_equal 2, Resque.size(:ivar)
51
+ assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
52
+ assert_equal 3, Resque.size(:ivar)
53
+
54
+ job = Resque.reserve(:ivar)
55
+
56
+ assert_kind_of Resque::Job, job
57
+ assert_equal SomeIvarJob, job.payload_class
58
+ assert_equal 20, job.args[0]
59
+ assert_equal '/tmp', job.args[1]
60
+
61
+ #assert Resque.reserve(:ivar)
62
+ #assert_equal nil, Resque.reserve(:ivar)
63
+ end
64
+
65
+ test "can remove jobs from a queue by way of an ivar" do
66
+ assert_equal 0, Resque.size(:ivar)
67
+ assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
68
+ assert Resque.enqueue(SomeIvarJob, 30, '/tmp')
69
+ assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
70
+ assert Resque::Job.create(:ivar, 'blah-job', 20, '/tmp')
71
+ assert Resque.enqueue(SomeIvarJob, 20, '/tmp')
72
+ assert_equal 5, Resque.size(:ivar)
73
+
74
+ assert Resque.dequeue(SomeIvarJob, 30, '/tmp')
75
+ assert_equal 4, Resque.size(:ivar)
76
+ assert Resque.dequeue(SomeIvarJob)
77
+ assert_equal 1, Resque.size(:ivar)
78
+ end
79
+
80
+ test "jobs have a nice #inspect" do
81
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
82
+ job = Resque.reserve(:jobs)
83
+ assert_equal '(Job{jobs} | SomeJob | [20, "/tmp"])', job.inspect
84
+ end
85
+
86
+ test "jobs can be destroyed" do
87
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
88
+ assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
89
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
90
+ assert Resque::Job.create(:jobs, 'BadJob', 30, '/tmp')
91
+ assert Resque::Job.create(:jobs, 'BadJob', 20, '/tmp')
92
+
93
+ assert_equal 5, Resque.size(:jobs)
94
+ assert_equal 2, Resque::Job.destroy(:jobs, 'SomeJob')
95
+ assert_equal 3, Resque.size(:jobs)
96
+ assert_equal 1, Resque::Job.destroy(:jobs, 'BadJob', 30, '/tmp')
97
+ assert_equal 2, Resque.size(:jobs)
98
+ end
99
+
100
+ test "jobs can test for equality" do
101
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
102
+ assert Resque::Job.create(:jobs, 'some-job', 20, '/tmp')
103
+ assert_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
104
+
105
+ assert Resque::Job.create(:jobs, 'SomeMethodJob', 20, '/tmp')
106
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
107
+ assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
108
+
109
+ assert Resque::Job.create(:jobs, 'SomeJob', 20, '/tmp')
110
+ assert Resque::Job.create(:jobs, 'SomeJob', 30, '/tmp')
111
+ assert_not_equal Resque.reserve(:jobs), Resque.reserve(:jobs)
112
+ end
113
+
114
+ test "can put jobs on a queue by way of a method" do
115
+ assert_equal 0, Resque.size(:method)
116
+ assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
117
+ assert Resque.enqueue(SomeMethodJob, 20, '/tmp')
118
+
119
+ job = Resque.reserve(:method)
120
+
121
+ assert_kind_of Resque::Job, job
122
+ assert_equal SomeMethodJob, job.payload_class
123
+ assert_equal 20, job.args[0]
124
+ assert_equal '/tmp', job.args[1]
125
+
126
+ assert Resque.reserve(:method)
127
+ assert_equal nil, Resque.reserve(:method)
128
+ end
129
+
130
+ test "needs to infer a queue with enqueue" do
131
+ assert_raises Resque::NoQueueError do
132
+ Resque.enqueue(SomeJob, 20, '/tmp')
133
+ end
134
+ end
135
+
136
+ test "validates job for queue presence" do
137
+ assert_raises Resque::NoQueueError do
138
+ Resque.validate(SomeJob)
139
+ end
140
+ end
141
+
142
+ test "can put items on a queue" do
143
+ assert Resque.push(:people, { 'name' => 'jon' })
144
+ end
145
+
146
+ test "can pull items off a queue" do
147
+ assert_equal({ 'name' => 'chris' }, Resque.pop(:people))
148
+ assert_equal({ 'name' => 'bob' }, Resque.pop(:people))
149
+ assert_equal({ 'name' => 'mark' }, Resque.pop(:people))
150
+ assert_equal nil, Resque.pop(:people)
151
+ end
152
+
153
+ test "knows how big a queue is" do
154
+ assert_equal 3, Resque.size(:people)
155
+
156
+ assert_equal({ 'name' => 'chris' }, Resque.pop(:people))
157
+ assert_equal 2, Resque.size(:people)
158
+
159
+ assert_equal({ 'name' => 'bob' }, Resque.pop(:people))
160
+ assert_equal({ 'name' => 'mark' }, Resque.pop(:people))
161
+ assert_equal 0, Resque.size(:people)
162
+ end
163
+
164
+ test "can peek at a queue" do
165
+ assert_equal({ 'name' => 'chris' }, Resque.peek(:people))
166
+ assert_equal 3, Resque.size(:people)
167
+ end
168
+
169
+ test "can peek multiple items on a queue" do
170
+ assert_equal({ 'name' => 'chris' }, Resque.peek(:people, 0, 1))
171
+ assert_equal({ 'name' => 'bob' }, Resque.peek(:people, 1, 1))
172
+ assert_equal({ 'name' => 'mark' }, Resque.peek(:people, 2, 1))
173
+
174
+ assert_equal([{ 'name' => 'bob' }, { 'name' => 'mark' }], Resque.peek(:people, 1, 2))
175
+ assert_equal([{ 'name' => 'chris' }, { 'name' => 'bob' }], Resque.peek(:people, 0, 2))
176
+ assert_equal([{ 'name' => 'chris' }, { 'name' => 'bob' }, { 'name' => 'mark' }], Resque.peek(:people, 0, 3))
177
+ assert_equal nil, Resque.peek(:people, 3)
178
+ assert_equal [], Resque.peek(:people, 3, 2)
179
+ end
180
+
181
+ test "knows what queues it is managing" do
182
+ assert_equal %w( people ), Resque.queues
183
+ Resque.push(:cars, { 'make' => 'bmw' })
184
+ assert_equal %w( cars people ), Resque.queues
185
+ end
186
+
187
+ test "queues are always a list" do
188
+ Resque.flushall
189
+ assert_equal [], Resque.queues
190
+ end
191
+
192
+ test "can delete a queue" do
193
+ Resque.push(:cars, { 'make' => 'bmw' })
194
+ assert_equal %w( cars people ), Resque.queues
195
+ Resque.remove_queue(:people)
196
+ assert_equal %w( cars ), Resque.queues
197
+ assert_equal nil, Resque.pop(:people)
198
+ end
199
+
200
+ test "keeps track of resque keys" do
201
+ assert_equal ["people"], Resque.keys
202
+ end
203
+
204
+ test "badly wants a class name, too" do
205
+ assert_raises Resque::NoClassError do
206
+ Resque::Job.create(:jobs, nil)
207
+ end
208
+ end
209
+
210
+ test "keeps stats" do
211
+ Resque::Job.create(:jobs, SomeJob, 20, '/tmp')
212
+ Resque::Job.create(:jobs, BadJob)
213
+ Resque::Job.create(:jobs, GoodJob)
214
+
215
+ Resque::Job.create(:others, GoodJob)
216
+ Resque::Job.create(:others, GoodJob)
217
+
218
+ stats = Resque.info
219
+ assert_equal 8, stats[:pending]
220
+
221
+ @worker = Resque::Worker.new(:jobs)
222
+ @worker.register_worker
223
+ 2.times { @worker.process }
224
+
225
+ job = @worker.reserve
226
+ @worker.working_on job
227
+
228
+ stats = Resque.info
229
+ assert_equal 1, stats[:working]
230
+ assert_equal 1, stats[:workers]
231
+
232
+ @worker.done_working
233
+
234
+ stats = Resque.info
235
+ assert_equal 3, stats[:queues]
236
+ assert_equal 3, stats[:processed]
237
+ assert_equal 1, stats[:failed]
238
+ assert_equal "localhost:27017/monque/monque", stats[:servers]
239
+ end
240
+
241
+ test "decode bad json" do
242
+ assert_raises Resque::Helpers::DecodeException do
243
+ Resque.decode("{\"error\":\"Module not found \\u002\"}")
244
+ end
245
+ end
246
+
247
+ test "inlining jobs" do
248
+ begin
249
+ Resque.inline = true
250
+ Resque.enqueue(SomeIvarJob, 20, '/tmp')
251
+ assert_equal 0, Resque.size(:ivar)
252
+ ensure
253
+ Resque.inline = false
254
+ end
255
+ end
256
+ end