2012-03-10 16:07:19 -05:00
|
|
|
require 'helper'
|
|
|
|
require 'sidekiq'
|
|
|
|
require 'sidekiq/web'
|
|
|
|
require 'rack/test'
|
|
|
|
|
2013-09-22 17:38:33 -04:00
|
|
|
class TestWeb < Sidekiq::Test
|
2014-03-08 01:41:10 -05:00
|
|
|
|
2012-03-10 16:07:19 -05:00
|
|
|
describe 'sidekiq web' do
|
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
def app
|
|
|
|
Sidekiq::Web
|
|
|
|
end
|
|
|
|
|
2012-12-02 23:18:31 -05:00
|
|
|
def job_params(job, score)
|
|
|
|
"#{score}-#{job['jid']}"
|
|
|
|
end
|
|
|
|
|
2012-03-10 16:07:19 -05:00
|
|
|
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
|
|
|
|
|
2014-05-16 00:12:44 -04:00
|
|
|
describe 'busy' do
|
|
|
|
|
|
|
|
it 'can display workers' do
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.incr('busy')
|
|
|
|
conn.sadd('processes', 'foo:1234')
|
|
|
|
conn.hmset('foo:1234', 'info', Sidekiq.dump_json('hostname' => 'foo', 'started_at' => Time.now.to_f), 'at', Time.now.to_f, 'busy', 4)
|
|
|
|
identity = 'foo:1234:workers'
|
|
|
|
hash = {:queue => 'critical', :payload => { 'class' => WebWorker.name, 'args' => [1,'abc'] }, :run_at => Time.now.to_i }
|
|
|
|
conn.hmset(identity, 1001, Sidekiq.dump_json(hash))
|
|
|
|
end
|
|
|
|
assert_equal ['1001'], Sidekiq::Workers.new.map { |pid, tid, data| tid }
|
|
|
|
|
|
|
|
get '/busy'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
assert_match(/status-active/, last_response.body)
|
|
|
|
assert_match(/critical/, last_response.body)
|
|
|
|
assert_match(/WebWorker/, last_response.body)
|
2013-04-22 17:14:19 -04:00
|
|
|
end
|
|
|
|
|
2014-05-16 00:12:44 -04:00
|
|
|
it 'can quiet a process' do
|
|
|
|
assert_nil Sidekiq.redis { |c| c.lpop "host:pid-signals" }
|
|
|
|
post '/busy', 'quiet' => '1', 'hostname' => 'host', 'pid' => 'pid'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'USR1', Sidekiq.redis { |c| c.lpop "host:pid-signals" }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can stop a process' do
|
|
|
|
assert_nil Sidekiq.redis { |c| c.lpop "host:pid-signals" }
|
|
|
|
post '/busy', 'stop' => '1', 'hostname' => 'host', 'pid' => 'pid'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'TERM', Sidekiq.redis { |c| c.lpop "host:pid-signals" }
|
|
|
|
end
|
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
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/foo/, last_response.body)
|
|
|
|
refute_match(/HardWorker/, last_response.body)
|
2012-03-17 12:41:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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')
|
2014-05-17 18:55:21 -04:00
|
|
|
refute conn.exists('queue:foo')
|
2012-05-05 01:23:43 -04:00
|
|
|
end
|
|
|
|
end
|
2012-11-25 21:43:48 -05:00
|
|
|
|
2012-10-23 19:11:14 -04:00
|
|
|
it 'can delete a job' do
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.rpush('queue:foo', "{}")
|
|
|
|
conn.rpush('queue:foo', "{\"foo\":\"bar\"}")
|
|
|
|
conn.rpush('queue:foo', "{\"foo2\":\"bar2\"}")
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/queues/foo'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
|
|
|
|
post '/queues/foo/delete', key_val: "{\"foo\":\"bar\"}"
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
refute conn.lrange('queue:foo', 0, -1).include?("{\"foo\":\"bar\"}")
|
|
|
|
end
|
|
|
|
end
|
2012-05-11 19:48:03 -04:00
|
|
|
|
|
|
|
it 'can display retries' do
|
|
|
|
get '/retries'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -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
|
2014-03-19 20:41:11 -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
|
2012-11-26 14:53:22 -05:00
|
|
|
params = add_retry
|
2013-07-27 19:04:06 -04:00
|
|
|
get '/retries/0-shouldntexist'
|
2012-05-11 19:48:03 -04:00
|
|
|
assert_equal 302, last_response.status
|
2012-11-26 14:53:22 -05:00
|
|
|
get "/retries/#{job_params(*params)}"
|
2012-05-11 19:48:03 -04:00
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/HardWorker/, last_response.body)
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
2012-07-26 19:08:15 -04:00
|
|
|
|
2012-11-26 14:53:22 -05:00
|
|
|
it 'handles missing retry' do
|
2013-07-27 19:04:06 -04:00
|
|
|
get "/retries/0-shouldntexist"
|
2012-11-26 14:53:22 -05:00
|
|
|
assert_equal 302, last_response.status
|
|
|
|
end
|
|
|
|
|
2012-06-12 21:59:43 -04:00
|
|
|
it 'can delete a single retry' do
|
2012-11-26 14:53:22 -05:00
|
|
|
params = add_retry
|
|
|
|
post "/retries/#{job_params(*params)}", 'delete' => 'Delete'
|
2012-06-12 21:59:43 -04:00
|
|
|
assert_equal 302, last_response.status
|
2012-06-18 07:59:25 -04:00
|
|
|
assert_equal 'http://example.org/retries', last_response.header['Location']
|
2012-07-26 19:08:15 -04:00
|
|
|
|
2012-06-12 21:59:43 -04:00
|
|
|
get "/retries"
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
refute_match(/#{params.first['args'][2]}/, last_response.body)
|
2012-06-12 21:59:43 -04:00
|
|
|
end
|
2012-07-26 19:08:15 -04:00
|
|
|
|
2012-11-25 21:43:48 -05:00
|
|
|
it 'can delete all retries' do
|
|
|
|
3.times { add_retry }
|
|
|
|
|
|
|
|
post "/retries/all/delete", 'delete' => 'Delete'
|
|
|
|
assert_equal 0, Sidekiq::RetrySet.new.size
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/retries', last_response.header['Location']
|
|
|
|
end
|
|
|
|
|
2012-06-12 23:32:13 -04:00
|
|
|
it 'can retry a single retry now' do
|
2012-11-26 14:53:22 -05:00
|
|
|
params = add_retry
|
|
|
|
post "/retries/#{job_params(*params)}", 'retry' => 'Retry'
|
2012-06-12 23:32:13 -04:00
|
|
|
assert_equal 302, last_response.status
|
2012-06-18 07:59:25 -04:00
|
|
|
assert_equal 'http://example.org/retries', last_response.header['Location']
|
2012-07-26 19:08:15 -04:00
|
|
|
|
2012-06-12 23:32:13 -04:00
|
|
|
get '/queues/default'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/#{params.first['args'][2]}/, last_response.body)
|
2012-11-26 14:53:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can display scheduled' do
|
|
|
|
get '/scheduled'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/found/, last_response.body)
|
|
|
|
refute_match(/HardWorker/, last_response.body)
|
2012-11-26 14:53:22 -05:00
|
|
|
|
|
|
|
add_scheduled
|
|
|
|
|
|
|
|
get '/scheduled'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
refute_match(/found/, last_response.body)
|
|
|
|
assert_match(/HardWorker/, last_response.body)
|
2012-06-12 23:32:13 -04:00
|
|
|
end
|
2012-05-11 19:48:03 -04:00
|
|
|
|
2013-07-27 18:49:35 -04:00
|
|
|
it 'can display a single scheduled job' do
|
|
|
|
params = add_scheduled
|
2013-07-27 19:04:06 -04:00
|
|
|
get '/scheduled/0-shouldntexist'
|
2013-07-27 18:49:35 -04:00
|
|
|
assert_equal 302, last_response.status
|
|
|
|
get "/scheduled/#{job_params(*params)}"
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/HardWorker/, last_response.body)
|
2013-07-27 18:49:35 -04:00
|
|
|
end
|
|
|
|
|
2013-07-27 19:04:06 -04:00
|
|
|
it 'handles missing scheduled job' do
|
|
|
|
get "/scheduled/0-shouldntexist"
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
end
|
|
|
|
|
2013-07-27 18:49:35 -04:00
|
|
|
it 'can add to queue a single scheduled job' do
|
|
|
|
params = add_scheduled
|
|
|
|
post "/scheduled/#{job_params(*params)}", 'add_to_queue' => true
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/scheduled', last_response.header['Location']
|
|
|
|
|
|
|
|
get '/queues/default'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/#{params.first['args'][2]}/, last_response.body)
|
2013-07-27 18:49:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can delete a single scheduled job' do
|
|
|
|
params = add_scheduled
|
|
|
|
post "/scheduled/#{job_params(*params)}", 'delete' => 'Delete'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/scheduled', last_response.header['Location']
|
|
|
|
|
|
|
|
get "/scheduled"
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
refute_match(/#{params.first['args'][2]}/, last_response.body)
|
2013-07-27 18:49:35 -04:00
|
|
|
end
|
|
|
|
|
2012-11-26 11:22:48 -05:00
|
|
|
it 'can delete scheduled' do
|
2012-11-26 14:53:22 -05:00
|
|
|
params = add_scheduled
|
2012-11-26 11:22:48 -05:00
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
assert_equal 1, conn.zcard('schedule')
|
2012-11-26 14:53:22 -05:00
|
|
|
post '/scheduled', 'key' => [job_params(*params)], 'delete' => 'Delete'
|
2012-11-26 11:22:48 -05:00
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/scheduled', last_response.header['Location']
|
|
|
|
assert_equal 0, conn.zcard('schedule')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-23 19:22:54 -04:00
|
|
|
it "can move scheduled to default queue" do
|
2013-07-17 00:20:42 -04:00
|
|
|
q = Sidekiq::Queue.new
|
2013-06-23 19:22:54 -04:00
|
|
|
params = add_scheduled
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
assert_equal 1, conn.zcard('schedule')
|
2013-07-17 00:20:42 -04:00
|
|
|
assert_equal 0, q.size
|
2013-06-23 19:22:54 -04:00
|
|
|
post '/scheduled', 'key' => [job_params(*params)], 'add_to_queue' => 'AddToQueue'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/scheduled', last_response.header['Location']
|
|
|
|
assert_equal 0, conn.zcard('schedule')
|
2013-07-17 00:20:42 -04:00
|
|
|
assert_equal 1, q.size
|
2013-06-23 19:22:54 -04:00
|
|
|
get '/queues/default'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/#{params[0]['args'][2]}/, last_response.body)
|
2013-06-23 19:22:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-25 21:43:48 -05:00
|
|
|
it 'can retry all retries' do
|
2014-03-19 20:41:11 -04:00
|
|
|
msg = add_retry.first
|
2012-11-25 21:43:48 -05:00
|
|
|
add_retry
|
|
|
|
|
|
|
|
post "/retries/all/retry", 'retry' => 'Retry'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/retries', last_response.header['Location']
|
|
|
|
assert_equal 2, Sidekiq::Queue.new("default").size
|
|
|
|
|
|
|
|
get '/queues/default'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
assert_match /#{msg['args'][2]}/, last_response.body
|
|
|
|
end
|
|
|
|
|
2013-10-30 18:12:26 -04:00
|
|
|
it 'escape job args and error messages' do
|
|
|
|
# on /retries page
|
|
|
|
params = add_xss_retry
|
|
|
|
get '/retries'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/FailWorker/, last_response.body)
|
2013-10-30 18:12:26 -04:00
|
|
|
|
|
|
|
assert last_response.body.include?( "fail message: <a>hello</a>" )
|
|
|
|
assert !last_response.body.include?( "fail message: <a>hello</a>" )
|
|
|
|
|
|
|
|
assert last_response.body.include?( "args\">"<a>hello</a>"<" )
|
|
|
|
assert !last_response.body.include?( "args\"><a>hello</a><" )
|
|
|
|
|
|
|
|
# on /workers page
|
|
|
|
Sidekiq.redis do |conn|
|
2014-03-08 16:57:24 -05:00
|
|
|
pro = 'foo:1234'
|
|
|
|
conn.sadd('processes', pro)
|
|
|
|
conn.hmset(pro, 'info', Sidekiq.dump_json('started_at' => Time.now.to_f), 'busy', 1, 'beat', Time.now.to_f)
|
|
|
|
identity = "#{pro}:workers"
|
2013-10-30 18:12:26 -04:00
|
|
|
hash = {:queue => 'critical', :payload => { 'class' => "FailWorker", 'args' => ["<a>hello</a>"] }, :run_at => Time.now.to_i }
|
2014-03-08 01:41:10 -05:00
|
|
|
conn.hmset(identity, 100001, Sidekiq.dump_json(hash))
|
|
|
|
conn.incr('busy')
|
2013-10-30 18:12:26 -04:00
|
|
|
end
|
|
|
|
|
2014-03-07 00:30:11 -05:00
|
|
|
get '/busy'
|
2013-10-30 18:12:26 -04:00
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/FailWorker/, last_response.body)
|
2013-10-30 18:12:26 -04:00
|
|
|
assert last_response.body.include?( "<a>hello</a>" )
|
|
|
|
assert !last_response.body.include?( "<a>hello</a>" )
|
|
|
|
|
|
|
|
|
|
|
|
# on /queues page
|
|
|
|
params = add_xss_retry # sorry, don't know how to easily make this show up on queues page otherwise.
|
|
|
|
post "/retries/#{job_params(*params)}", 'retry' => 'Retry'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
|
|
|
|
get '/queues/foo'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
assert last_response.body.include?( "<a>hello</a>" )
|
|
|
|
assert !last_response.body.include?( "<a>hello</a>" )
|
|
|
|
end
|
|
|
|
|
2012-08-20 18:28:14 -04:00
|
|
|
it 'can show user defined tab' do
|
2012-10-28 22:49:43 -04:00
|
|
|
begin
|
|
|
|
Sidekiq::Web.tabs['Custom Tab'] = '/custom'
|
2012-08-20 18:28:14 -04:00
|
|
|
|
2012-10-28 22:49:43 -04:00
|
|
|
get '/'
|
|
|
|
assert_match 'Custom Tab', last_response.body
|
2012-08-20 18:28:14 -04:00
|
|
|
|
2012-10-28 22:49:43 -04:00
|
|
|
ensure
|
|
|
|
Sidekiq::Web.tabs.delete 'Custom Tab'
|
|
|
|
end
|
2012-08-20 18:28:14 -04:00
|
|
|
end
|
|
|
|
|
2013-02-20 15:04:19 -05:00
|
|
|
it 'can display home' do
|
|
|
|
get '/'
|
2012-12-11 09:49:16 -05:00
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
2013-10-21 15:07:18 -04:00
|
|
|
Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
|
|
|
|
it 'can show user defined tab with custom locales' do
|
|
|
|
begin
|
|
|
|
Sidekiq::Web.tabs['Custom Tab'] = '/custom'
|
|
|
|
Sidekiq::Web.get('/custom') do
|
|
|
|
t('translated_text')
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/custom'
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/Changed text/, last_response.body)
|
2013-10-21 15:07:18 -04:00
|
|
|
|
|
|
|
ensure
|
|
|
|
Sidekiq::Web.tabs.delete 'Custom Tab'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-26 14:34:46 -05:00
|
|
|
describe 'stats' do
|
2014-03-08 01:41:10 -05:00
|
|
|
include Sidekiq::Util
|
|
|
|
|
2013-01-26 14:34:46 -05:00
|
|
|
before do
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.set("stat:processed", 5)
|
|
|
|
conn.set("stat:failed", 2)
|
|
|
|
end
|
|
|
|
2.times { add_retry }
|
|
|
|
3.times { add_scheduled }
|
2013-02-18 10:15:51 -05:00
|
|
|
4.times { add_worker }
|
|
|
|
|
2013-01-26 14:34:46 -05:00
|
|
|
get '/dashboard/stats'
|
|
|
|
@response = Sidekiq.load_json(last_response.body)
|
2012-12-13 06:53:54 -05:00
|
|
|
end
|
2012-12-28 20:55:00 -05:00
|
|
|
|
2013-01-26 14:34:46 -05:00
|
|
|
it 'can refresh dashboard stats' do
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for sidekiq" do
|
|
|
|
it 'are namespaced' do
|
|
|
|
assert_includes @response.keys, "sidekiq"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports processed' do
|
2013-02-18 10:15:51 -05:00
|
|
|
assert_equal 5, @response["sidekiq"]["processed"]
|
2013-01-26 14:34:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports failed' do
|
2013-02-18 10:15:51 -05:00
|
|
|
assert_equal 2, @response["sidekiq"]["failed"]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports busy' do
|
|
|
|
assert_equal 4, @response["sidekiq"]["busy"]
|
2013-01-26 14:34:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports retries' do
|
2013-02-18 10:15:51 -05:00
|
|
|
assert_equal 2, @response["sidekiq"]["retries"]
|
2013-01-26 14:34:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports scheduled' do
|
2013-02-18 10:15:51 -05:00
|
|
|
assert_equal 3, @response["sidekiq"]["scheduled"]
|
2013-01-26 14:34:46 -05:00
|
|
|
end
|
2013-10-04 03:18:04 -04:00
|
|
|
|
|
|
|
it 'reports latency' do
|
2013-10-04 12:44:45 -04:00
|
|
|
assert_equal 0, @response["sidekiq"]["default_latency"]
|
2013-10-04 03:18:04 -04:00
|
|
|
end
|
2013-01-26 14:34:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "for redis" do
|
|
|
|
it 'are namespaced' do
|
|
|
|
assert_includes @response.keys, "redis"
|
|
|
|
end
|
2014-05-09 18:55:04 -04:00
|
|
|
|
2014-05-09 19:03:50 -04:00
|
|
|
it 'reports version' do
|
|
|
|
assert_includes @response["redis"].keys, "redis_version"
|
|
|
|
end
|
|
|
|
|
2014-05-09 18:55:04 -04:00
|
|
|
it 'reports uptime' do
|
|
|
|
assert_includes @response["redis"].keys, "uptime_in_days"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports connected clients' do
|
|
|
|
assert_includes @response["redis"].keys, "connected_clients"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports user memory' do
|
|
|
|
assert_includes @response["redis"].keys, "used_memory_human"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports memory peak' do
|
|
|
|
assert_includes @response["redis"].keys, "used_memory_peak_human"
|
|
|
|
end
|
2013-01-26 14:34:46 -05:00
|
|
|
end
|
2012-12-13 06:53:54 -05:00
|
|
|
end
|
|
|
|
|
2014-02-09 17:56:01 -05:00
|
|
|
describe 'dead jobs' do
|
|
|
|
it 'shows empty index' do
|
|
|
|
get 'morgue'
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
2014-02-10 00:17:05 -05:00
|
|
|
|
2014-02-09 17:56:01 -05:00
|
|
|
it 'shows index with jobs' do
|
|
|
|
(_, score) = add_dead
|
|
|
|
get 'morgue'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/#{score}/, last_response.body)
|
2014-02-09 17:56:01 -05:00
|
|
|
end
|
2014-02-10 00:17:05 -05:00
|
|
|
|
|
|
|
it 'can delete all dead' do
|
|
|
|
3.times { add_dead }
|
|
|
|
|
|
|
|
assert_equal 3, Sidekiq::DeadSet.new.size
|
|
|
|
post "/morgue/all/delete", 'delete' => 'Delete'
|
|
|
|
assert_equal 0, Sidekiq::DeadSet.new.size
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/morgue', last_response.header['Location']
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can retry a dead job' do
|
|
|
|
params = add_dead
|
|
|
|
post "/morgue/#{job_params(*params)}", 'retry' => 'Retry'
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
assert_equal 'http://example.org/morgue', last_response.header['Location']
|
|
|
|
|
|
|
|
get '/queues/foo'
|
|
|
|
assert_equal 200, last_response.status
|
2014-03-19 20:41:11 -04:00
|
|
|
assert_match(/#{params.first['args'][2]}/, last_response.body)
|
2014-02-10 00:17:05 -05:00
|
|
|
end
|
2014-02-09 17:56:01 -05:00
|
|
|
end
|
|
|
|
|
2012-05-26 21:38:55 -04:00
|
|
|
def add_scheduled
|
2012-11-26 11:22:48 -05:00
|
|
|
score = Time.now.to_f
|
2012-05-26 21:38:55 -04:00
|
|
|
msg = { 'class' => 'HardWorker',
|
|
|
|
'args' => ['bob', 1, Time.now.to_f],
|
2013-12-07 23:29:07 -05:00
|
|
|
'jid' => SecureRandom.hex(12) }
|
2012-05-26 21:38:55 -04:00
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('schedule', score, Sidekiq.dump_json(msg))
|
|
|
|
end
|
2012-11-26 14:53:22 -05:00
|
|
|
[msg, score]
|
2012-05-26 21:38:55 -04:00
|
|
|
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,
|
2014-02-09 18:08:21 -05:00
|
|
|
'failed_at' => Time.now.to_f,
|
2013-12-07 23:29:07 -05:00
|
|
|
'jid' => SecureRandom.hex(12) }
|
2012-05-11 19:48:03 -04:00
|
|
|
score = Time.now.to_f
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|
|
|
|
end
|
2012-11-26 14:53:22 -05:00
|
|
|
[msg, score]
|
2012-05-11 19:48:03 -04:00
|
|
|
end
|
2014-02-09 17:56:01 -05:00
|
|
|
|
|
|
|
def add_dead
|
|
|
|
msg = { 'class' => 'HardWorker',
|
|
|
|
'args' => ['bob', 1, Time.now.to_f],
|
2014-02-10 00:17:05 -05:00
|
|
|
'queue' => 'foo',
|
2014-02-09 17:56:01 -05:00
|
|
|
'error_message' => 'Some fake message',
|
|
|
|
'error_class' => 'RuntimeError',
|
|
|
|
'retry_count' => 0,
|
|
|
|
'failed_at' => Time.now.utc,
|
|
|
|
'jid' => SecureRandom.hex(12) }
|
|
|
|
score = Time.now.to_f
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('dead', score, Sidekiq.dump_json(msg))
|
|
|
|
end
|
|
|
|
[msg, score]
|
|
|
|
end
|
2013-02-18 10:15:51 -05:00
|
|
|
|
2013-10-30 18:12:26 -04:00
|
|
|
def add_xss_retry
|
|
|
|
msg = { 'class' => 'FailWorker',
|
|
|
|
'args' => ['<a>hello</a>'],
|
|
|
|
'queue' => 'foo',
|
|
|
|
'error_message' => 'fail message: <a>hello</a>',
|
|
|
|
'error_class' => 'RuntimeError',
|
|
|
|
'retry_count' => 0,
|
2014-02-09 18:08:21 -05:00
|
|
|
'failed_at' => Time.now.to_f,
|
2013-12-07 23:29:07 -05:00
|
|
|
'jid' => SecureRandom.hex(12) }
|
2013-10-30 18:12:26 -04:00
|
|
|
score = Time.now.to_f
|
|
|
|
Sidekiq.redis do |conn|
|
|
|
|
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|
|
|
|
end
|
|
|
|
[msg, score]
|
|
|
|
end
|
|
|
|
|
2013-02-18 10:15:51 -05:00
|
|
|
def add_worker
|
2014-03-08 01:41:10 -05:00
|
|
|
key = "#{hostname}:#{$$}"
|
2013-02-18 10:15:51 -05:00
|
|
|
msg = "{\"queue\":\"default\",\"payload\":{\"retry\":true,\"queue\":\"default\",\"timeout\":20,\"backtrace\":5,\"class\":\"HardWorker\",\"args\":[\"bob\",10,5],\"jid\":\"2b5ad2b016f5e063a1c62872\"},\"run_at\":1361208995}"
|
|
|
|
Sidekiq.redis do |conn|
|
2014-03-08 01:41:10 -05:00
|
|
|
conn.multi do
|
|
|
|
conn.sadd("processes", key)
|
2014-03-08 17:44:19 -05:00
|
|
|
conn.hmset(key, 'busy', 4)
|
2014-03-08 01:41:10 -05:00
|
|
|
conn.hmset("#{key}:workers", Time.now.to_f, msg)
|
|
|
|
end
|
2013-02-18 10:15:51 -05:00
|
|
|
end
|
|
|
|
end
|
2012-03-10 16:07:19 -05:00
|
|
|
end
|
|
|
|
end
|