2012-03-10 16:07:19 -05:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq'
|
|
|
|
require 'sidekiq/web'
|
|
|
|
require 'rack/test'
|
|
|
|
|
|
|
|
class TestWeb < MiniTest::Unit::TestCase
|
|
|
|
describe 'sidekiq web' do
|
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
def app
|
|
|
|
Sidekiq::Web
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2012-03-14 00:19:46 -04:00
|
|
|
Sidekiq.redis = REDIS
|
2012-03-28 22:16:54 -04:00
|
|
|
Sidekiq.redis {|c| c.flushdb }
|
2012-03-10 16:07:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
class WebWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(a, b)
|
|
|
|
a + b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-08 20:20:11 -04:00
|
|
|
it 'can display home' do
|
2012-03-10 16:07:19 -05:00
|
|
|
get '/'
|
|
|
|
assert_equal 200, last_response.status
|
2012-05-12 02:28:30 -04:00
|
|
|
assert_match /Sidekiq is idle/, last_response.body
|
|
|
|
refute_match /default/, last_response.body
|
2012-06-08 20:20:11 -04:00
|
|
|
end
|
2012-03-10 16:07:19 -05:00
|
|
|
|
2012-06-08 20:20:11 -04:00
|
|
|
it 'can display queues' do
|
2012-04-01 22:53:45 -04:00
|
|
|
assert Sidekiq::Client.push('queue' => :foo, 'class' => WebWorker, 'args' => [1, 3])
|
2012-03-10 16:07:19 -05:00
|
|
|
|
2012-06-08 20:20:11 -04:00
|
|
|
get '/queues'
|
2012-03-10 16:07:19 -05:00
|
|
|
assert_equal 200, last_response.status
|
2012-05-12 02:28:30 -04:00
|
|
|
assert_match /foo/, last_response.body
|
2012-06-08 20:20:11 -04:00
|
|
|
refute_match /HardWorker/, last_response.body
|
2012-03-17 12:41:24 -04:00
|
|
|
end
|
|
|
|
|
2012-05-05 01:23:43 -04:00
|
|
|
it 'handles missing retry' do
|
|
|
|
get '/retries/12391982.123'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
end
|
|
|
|
|
2012-03-17 12:41:24 -04:00
|
|
|
it 'handles queue view' do
|
|
|
|
get '/queues/default'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
2012-05-05 01:23:43 -04:00
|
|
|
it 'can delete a queue' do
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.rpush('queue:foo', '{}')
|
|
|
|
conn.sadd('queues', 'foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/queues/foo'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
|
|
|
|
post '/queues/foo'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
refute conn.smembers('queues').include?('foo')
|
|
|
|
end
|
|
|
|
end
|
2012-05-11 19:48:03 -04:00
|
|
|
|
2012-05-26 21:38:55 -04:00
|
|
|
it 'can display scheduled' do
|
|
|
|
get '/scheduled'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
assert_match /found/, last_response.body
|
|
|
|
refute_match /HardWorker/, last_response.body
|
|
|
|
|
|
|
|
add_scheduled
|
|
|
|
|
|
|
|
get '/scheduled'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
refute_match /found/, last_response.body
|
|
|
|
assert_match /HardWorker/, last_response.body
|
|
|
|
end
|
|
|
|
|
2012-05-11 19:48:03 -04:00
|
|
|
it 'can display retries' do
|
|
|
|
get '/retries'
|
|
|
|
assert_equal 200, last_response.status
|
2012-05-12 02:28:30 -04:00
|
|
|
assert_match /found/, last_response.body
|
|
|
|
refute_match /HardWorker/, last_response.body
|
2012-05-11 19:48:03 -04:00
|
|
|
|
|
|
|
add_retry
|
|
|
|
|
|
|
|
get '/retries'
|
|
|
|
assert_equal 200, last_response.status
|
2012-05-12 02:28:30 -04:00
|
|
|
refute_match /found/, last_response.body
|
|
|
|
assert_match /HardWorker/, last_response.body
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can display a single retry' do
|
|
|
|
get '/retries/12938712.123333'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
_, score = add_retry
|
|
|
|
|
|
|
|
get "/retries/#{score}"
|
|
|
|
assert_equal 200, last_response.status
|
2012-05-12 02:28:30 -04:00
|
|
|
assert_match /HardWorker/, last_response.body
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
|
|
|
|
2012-05-26 21:38:55 -04:00
|
|
|
def add_scheduled
|
|
|
|
msg = { 'class' => 'HardWorker',
|
|
|
|
'args' => ['bob', 1, Time.now.to_f],
|
|
|
|
'at' => Time.now.to_f }
|
|
|
|
score = Time.now.to_f
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('schedule', score, Sidekiq.dump_json(msg))
|
|
|
|
end
|
|
|
|
[msg, score]
|
|
|
|
end
|
|
|
|
|
2012-05-11 19:48:03 -04:00
|
|
|
def add_retry
|
|
|
|
msg = { 'class' => 'HardWorker',
|
|
|
|
'args' => ['bob', 1, Time.now.to_f],
|
|
|
|
'queue' => 'default',
|
|
|
|
'error_message' => 'Some fake message',
|
|
|
|
'error_class' => 'RuntimeError',
|
|
|
|
'retry_count' => 0,
|
|
|
|
'failed_at' => Time.now.utc, }
|
|
|
|
score = Time.now.to_f
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|
|
|
|
end
|
|
|
|
[msg, score]
|
|
|
|
end
|
2012-03-10 16:07:19 -05:00
|
|
|
end
|
|
|
|
end
|