kulesa-sidekiq 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.gitignore +6 -0
  2. data/.rvmrc +4 -0
  3. data/COMM-LICENSE +83 -0
  4. data/Changes.md +207 -0
  5. data/Gemfile +12 -0
  6. data/LICENSE +22 -0
  7. data/README.md +61 -0
  8. data/Rakefile +9 -0
  9. data/bin/client +7 -0
  10. data/bin/sidekiq +14 -0
  11. data/bin/sidekiqctl +74 -0
  12. data/config.ru +18 -0
  13. data/examples/chef/cookbooks/sidekiq/README.rdoc +11 -0
  14. data/examples/chef/cookbooks/sidekiq/recipes/default.rb +55 -0
  15. data/examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb +8 -0
  16. data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb +219 -0
  17. data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb +22 -0
  18. data/examples/clockwork.rb +44 -0
  19. data/examples/config.yml +10 -0
  20. data/examples/monitrc.conf +6 -0
  21. data/examples/por.rb +27 -0
  22. data/examples/scheduling.rb +37 -0
  23. data/examples/sinkiq.rb +59 -0
  24. data/examples/web-ui.png +0 -0
  25. data/lib/sidekiq.rb +98 -0
  26. data/lib/sidekiq/capistrano.rb +35 -0
  27. data/lib/sidekiq/cli.rb +214 -0
  28. data/lib/sidekiq/client.rb +72 -0
  29. data/lib/sidekiq/extensions/action_mailer.rb +26 -0
  30. data/lib/sidekiq/extensions/active_record.rb +27 -0
  31. data/lib/sidekiq/extensions/generic_proxy.rb +21 -0
  32. data/lib/sidekiq/fetch.rb +76 -0
  33. data/lib/sidekiq/logging.rb +46 -0
  34. data/lib/sidekiq/manager.rb +163 -0
  35. data/lib/sidekiq/middleware/chain.rb +96 -0
  36. data/lib/sidekiq/middleware/client/unique_jobs.rb +36 -0
  37. data/lib/sidekiq/middleware/server/active_record.rb +13 -0
  38. data/lib/sidekiq/middleware/server/exception_handler.rb +38 -0
  39. data/lib/sidekiq/middleware/server/failure_jobs.rb +25 -0
  40. data/lib/sidekiq/middleware/server/logging.rb +31 -0
  41. data/lib/sidekiq/middleware/server/retry_jobs.rb +69 -0
  42. data/lib/sidekiq/middleware/server/timeout.rb +21 -0
  43. data/lib/sidekiq/middleware/server/unique_jobs.rb +17 -0
  44. data/lib/sidekiq/processor.rb +92 -0
  45. data/lib/sidekiq/rails.rb +21 -0
  46. data/lib/sidekiq/redis_connection.rb +27 -0
  47. data/lib/sidekiq/retry.rb +59 -0
  48. data/lib/sidekiq/testing.rb +44 -0
  49. data/lib/sidekiq/testing/inline.rb +37 -0
  50. data/lib/sidekiq/util.rb +40 -0
  51. data/lib/sidekiq/version.rb +3 -0
  52. data/lib/sidekiq/web.rb +185 -0
  53. data/lib/sidekiq/worker.rb +62 -0
  54. data/lib/sidekiq/yaml_patch.rb +21 -0
  55. data/myapp/.gitignore +15 -0
  56. data/myapp/Capfile +5 -0
  57. data/myapp/Gemfile +19 -0
  58. data/myapp/Rakefile +7 -0
  59. data/myapp/app/controllers/application_controller.rb +3 -0
  60. data/myapp/app/controllers/work_controller.rb +38 -0
  61. data/myapp/app/helpers/application_helper.rb +2 -0
  62. data/myapp/app/mailers/.gitkeep +0 -0
  63. data/myapp/app/mailers/user_mailer.rb +9 -0
  64. data/myapp/app/models/.gitkeep +0 -0
  65. data/myapp/app/models/post.rb +5 -0
  66. data/myapp/app/views/layouts/application.html.erb +14 -0
  67. data/myapp/app/views/user_mailer/greetings.html.erb +3 -0
  68. data/myapp/app/views/work/index.html.erb +1 -0
  69. data/myapp/app/workers/hard_worker.rb +10 -0
  70. data/myapp/config.ru +4 -0
  71. data/myapp/config/application.rb +59 -0
  72. data/myapp/config/boot.rb +6 -0
  73. data/myapp/config/database.yml +25 -0
  74. data/myapp/config/deploy.rb +15 -0
  75. data/myapp/config/environment.rb +5 -0
  76. data/myapp/config/environments/development.rb +38 -0
  77. data/myapp/config/environments/production.rb +67 -0
  78. data/myapp/config/environments/test.rb +37 -0
  79. data/myapp/config/initializers/backtrace_silencers.rb +7 -0
  80. data/myapp/config/initializers/inflections.rb +15 -0
  81. data/myapp/config/initializers/mime_types.rb +5 -0
  82. data/myapp/config/initializers/secret_token.rb +7 -0
  83. data/myapp/config/initializers/session_store.rb +8 -0
  84. data/myapp/config/initializers/sidekiq.rb +6 -0
  85. data/myapp/config/initializers/wrap_parameters.rb +14 -0
  86. data/myapp/config/locales/en.yml +5 -0
  87. data/myapp/config/routes.rb +10 -0
  88. data/myapp/db/migrate/20120123214055_create_posts.rb +10 -0
  89. data/myapp/db/seeds.rb +7 -0
  90. data/myapp/lib/assets/.gitkeep +0 -0
  91. data/myapp/lib/tasks/.gitkeep +0 -0
  92. data/myapp/log/.gitkeep +0 -0
  93. data/myapp/script/rails +6 -0
  94. data/sidekiq.gemspec +27 -0
  95. data/test/config.yml +9 -0
  96. data/test/fake_env.rb +0 -0
  97. data/test/helper.rb +16 -0
  98. data/test/test_cli.rb +168 -0
  99. data/test/test_client.rb +119 -0
  100. data/test/test_extensions.rb +69 -0
  101. data/test/test_manager.rb +51 -0
  102. data/test/test_middleware.rb +92 -0
  103. data/test/test_processor.rb +32 -0
  104. data/test/test_retry.rb +125 -0
  105. data/test/test_stats.rb +68 -0
  106. data/test/test_testing.rb +97 -0
  107. data/test/test_testing_inline.rb +75 -0
  108. data/test/test_web.rb +122 -0
  109. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  110. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  111. data/web/assets/javascripts/application.js +20 -0
  112. data/web/assets/javascripts/vendor/bootstrap.js +12 -0
  113. data/web/assets/javascripts/vendor/bootstrap/bootstrap-alert.js +91 -0
  114. data/web/assets/javascripts/vendor/bootstrap/bootstrap-button.js +98 -0
  115. data/web/assets/javascripts/vendor/bootstrap/bootstrap-carousel.js +154 -0
  116. data/web/assets/javascripts/vendor/bootstrap/bootstrap-collapse.js +136 -0
  117. data/web/assets/javascripts/vendor/bootstrap/bootstrap-dropdown.js +92 -0
  118. data/web/assets/javascripts/vendor/bootstrap/bootstrap-modal.js +210 -0
  119. data/web/assets/javascripts/vendor/bootstrap/bootstrap-popover.js +95 -0
  120. data/web/assets/javascripts/vendor/bootstrap/bootstrap-scrollspy.js +125 -0
  121. data/web/assets/javascripts/vendor/bootstrap/bootstrap-tab.js +130 -0
  122. data/web/assets/javascripts/vendor/bootstrap/bootstrap-tooltip.js +270 -0
  123. data/web/assets/javascripts/vendor/bootstrap/bootstrap-transition.js +51 -0
  124. data/web/assets/javascripts/vendor/bootstrap/bootstrap-typeahead.js +271 -0
  125. data/web/assets/javascripts/vendor/jquery.js +9266 -0
  126. data/web/assets/javascripts/vendor/jquery.timeago.js +148 -0
  127. data/web/assets/stylesheets/application.css +27 -0
  128. data/web/assets/stylesheets/vendor/bootstrap-responsive.css +567 -0
  129. data/web/assets/stylesheets/vendor/bootstrap.css +3365 -0
  130. data/web/views/index.slim +48 -0
  131. data/web/views/layout.slim +26 -0
  132. data/web/views/queue.slim +11 -0
  133. data/web/views/retries.slim +29 -0
  134. data/web/views/retry.slim +52 -0
  135. metadata +371 -0
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+ require 'sidekiq'
3
+ require 'sidekiq/manager'
4
+
5
+ # for TimedQueue
6
+ require 'connection_pool'
7
+
8
+ class TestManager < MiniTest::Unit::TestCase
9
+ describe 'with redis' do
10
+ before do
11
+ Sidekiq.redis = REDIS
12
+ Sidekiq.redis {|c| c.flushdb }
13
+ $processed = 0
14
+ $mutex = Mutex.new
15
+ end
16
+
17
+ class IntegrationWorker
18
+ include Sidekiq::Worker
19
+ sidekiq_options :queue => 'foo'
20
+
21
+ def perform(a, b)
22
+ $mutex.synchronize do
23
+ $processed += 1
24
+ end
25
+ a + b
26
+ end
27
+ end
28
+
29
+ it 'processes messages' do
30
+ IntegrationWorker.perform_async(1, 2)
31
+ IntegrationWorker.perform_async(1, 3)
32
+
33
+ q = TimedQueue.new
34
+ mgr = Sidekiq::Manager.new(:queues => [:foo], :concurrency => 2)
35
+ mgr.when_done do |_|
36
+ q << 'done' if $processed == 2
37
+ end
38
+ mgr.start!
39
+ result = q.timed_pop(1.0)
40
+ assert_equal 'done', result
41
+ mgr.stop
42
+ mgr.terminate
43
+
44
+ # Gross bloody hack because I can't get the actor threads
45
+ # to shut down cleanly in the test. Need @bascule's help here.
46
+ (Thread.list - [Thread.current]).each do |t|
47
+ t.raise Interrupt
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,92 @@
1
+ require 'helper'
2
+ require 'sidekiq/middleware/chain'
3
+ require 'sidekiq/middleware/server/unique_jobs'
4
+ require 'sidekiq/processor'
5
+
6
+ class TestMiddleware < MiniTest::Unit::TestCase
7
+ describe 'middleware chain' do
8
+ before do
9
+ $errors = []
10
+ Sidekiq.redis = REDIS
11
+ end
12
+
13
+ it 'handles errors' do
14
+ handler = Sidekiq::Middleware::Server::ExceptionHandler.new
15
+
16
+ assert_raises ArgumentError do
17
+ handler.call('', { :a => 1 }, 'default') do
18
+ raise ArgumentError
19
+ end
20
+ end
21
+ assert_equal 1, $errors.size
22
+ assert_equal({ :a => 1 }, $errors[0][:parameters])
23
+ end
24
+
25
+ class CustomMiddleware
26
+ def initialize(name, recorder)
27
+ @name = name
28
+ @recorder = recorder
29
+ end
30
+
31
+ def call(*args)
32
+ @recorder << [@name, 'before']
33
+ yield
34
+ @recorder << [@name, 'after']
35
+ end
36
+ end
37
+
38
+ it 'supports custom middleware' do
39
+ chain = Sidekiq::Middleware::Chain.new
40
+ chain.add CustomMiddleware, 1, []
41
+
42
+ assert_equal CustomMiddleware, chain.entries.last.klass
43
+ end
44
+
45
+ class CustomWorker
46
+ include Sidekiq::Worker
47
+ def perform(recorder)
48
+ recorder << ['work_performed']
49
+ end
50
+ end
51
+
52
+ class NonYieldingMiddleware
53
+ def call(*args)
54
+ end
55
+ end
56
+
57
+ it 'executes middleware in the proper order' do
58
+ recorder = []
59
+ msg = { 'class' => CustomWorker.to_s, 'args' => [recorder] }
60
+
61
+ Sidekiq.server_middleware do |chain|
62
+ # should only add once, second should be ignored
63
+ 2.times { |i| chain.add CustomMiddleware, i.to_s, recorder }
64
+ end
65
+
66
+ boss = MiniTest::Mock.new
67
+ processor = Sidekiq::Processor.new(boss)
68
+ boss.expect(:processor_done!, nil, [processor])
69
+ processor.process(msg, 'default')
70
+ assert_equal %w(0 before work_performed 0 after), recorder.flatten
71
+ end
72
+
73
+ it 'allows middleware to abruptly stop processing rest of chain' do
74
+ recorder = []
75
+ chain = Sidekiq::Middleware::Chain.new
76
+ chain.add NonYieldingMiddleware
77
+ chain.add CustomMiddleware, 1, recorder
78
+
79
+ final_action = nil
80
+ chain.invoke { final_action = true }
81
+ assert_equal nil, final_action
82
+ assert_equal [], recorder
83
+ end
84
+ end
85
+ end
86
+
87
+ class FakeAirbrake
88
+ def self.notify(ex, hash)
89
+ $errors << hash
90
+ end
91
+ end
92
+ Airbrake = FakeAirbrake
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+ require 'sidekiq/processor'
3
+
4
+ class TestProcessor < MiniTest::Unit::TestCase
5
+ describe 'with mock setup' do
6
+ before do
7
+ $invokes = 0
8
+ $errors = []
9
+ @boss = MiniTest::Mock.new
10
+ Celluloid.logger = nil
11
+ Sidekiq.redis = REDIS
12
+ end
13
+
14
+ class MockWorker
15
+ include Sidekiq::Worker
16
+ def perform(args)
17
+ raise "kerboom!" if args == 'boom'
18
+ $invokes += 1
19
+ end
20
+ end
21
+
22
+ it 'processes as expected' do
23
+ msg = { 'class' => MockWorker.to_s, 'args' => ['myarg'] }
24
+ processor = ::Sidekiq::Processor.new(@boss)
25
+ @boss.expect(:processor_done!, nil, [processor])
26
+ processor.process(msg, 'default')
27
+ @boss.verify
28
+ assert_equal 1, $invokes
29
+ assert_equal 0, $errors.size
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,125 @@
1
+ require 'helper'
2
+ require 'multi_json'
3
+ require 'sidekiq/retry'
4
+ require 'sidekiq/middleware/server/retry_jobs'
5
+
6
+ class TestRetry < MiniTest::Unit::TestCase
7
+ describe 'middleware' do
8
+ before do
9
+ @redis = MiniTest::Mock.new
10
+ # Ugh, this is terrible.
11
+ Sidekiq.instance_variable_set(:@redis, @redis)
12
+
13
+ def @redis.with; yield self; end
14
+ end
15
+
16
+ it 'allows disabling retry' do
17
+ msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => false }
18
+ msg2 = msg.dup
19
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
20
+ assert_raises RuntimeError do
21
+ handler.call('', msg2, 'default') do
22
+ raise "kerblammo!"
23
+ end
24
+ end
25
+ assert_equal msg, msg2
26
+ end
27
+
28
+ it 'saves backtraces' do
29
+ @redis.expect :zadd, 1, ['retry', String, String]
30
+ msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'backtrace' => true }
31
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
32
+ c = nil
33
+ assert_raises RuntimeError do
34
+ handler.call('', msg, 'default') do
35
+ c = caller(0); raise "kerblammo!"
36
+ end
37
+ end
38
+ assert msg["error_backtrace"]
39
+ assert_equal c, msg["error_backtrace"]
40
+ end
41
+
42
+ it 'saves partial backtraces' do
43
+ @redis.expect :zadd, 1, ['retry', String, String]
44
+ msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true, 'backtrace' => 3 }
45
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
46
+ c = nil
47
+ assert_raises RuntimeError do
48
+ handler.call('', msg, 'default') do
49
+ c = caller(0)[0..3]; raise "kerblammo!"
50
+ end
51
+ end
52
+ assert msg["error_backtrace"]
53
+ assert_equal c, msg["error_backtrace"]
54
+ end
55
+
56
+ it 'handles a new failed message' do
57
+ @redis.expect :zadd, 1, ['retry', String, String]
58
+ msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
59
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
60
+ assert_raises RuntimeError do
61
+ handler.call('', msg, 'default') do
62
+ raise "kerblammo!"
63
+ end
64
+ end
65
+ assert_equal 'default', msg["queue"]
66
+ assert_equal 'kerblammo!', msg["error_message"]
67
+ assert_equal 'RuntimeError', msg["error_class"]
68
+ assert_equal 0, msg["retry_count"]
69
+ refute msg["error_backtrace"]
70
+ assert msg["failed_at"]
71
+ @redis.verify
72
+ end
73
+
74
+ it 'handles a recurring failed message' do
75
+ @redis.expect :zadd, 1, ['retry', String, String]
76
+ now = Time.now.utc
77
+ msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], 'retry' => true, "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>10}
78
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
79
+ assert_raises RuntimeError do
80
+ handler.call('', msg, 'default') do
81
+ raise "kerblammo!"
82
+ end
83
+ end
84
+ assert_equal 'default', msg["queue"]
85
+ assert_equal 'kerblammo!', msg["error_message"]
86
+ assert_equal 'RuntimeError', msg["error_class"]
87
+ assert_equal 11, msg["retry_count"]
88
+ assert msg["failed_at"]
89
+ @redis.verify
90
+ end
91
+
92
+ it 'throws away old messages after too many retries' do
93
+ now = Time.now.utc
94
+ msg = {"class"=>"Bob", "args"=>[1, 2, "foo"], "queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>25}
95
+ handler = Sidekiq::Middleware::Server::RetryJobs.new
96
+ assert_raises RuntimeError do
97
+ handler.call('', msg, 'default') do
98
+ raise "kerblammo!"
99
+ end
100
+ end
101
+ @redis.verify
102
+ end
103
+ end
104
+
105
+ describe 'poller' do
106
+ before do
107
+ @redis = MiniTest::Mock.new
108
+ Sidekiq.instance_variable_set(:@redis, @redis)
109
+
110
+ def @redis.with; yield self; end
111
+ end
112
+
113
+ it 'should poll like a bad mother...SHUT YO MOUTH' do
114
+ fake_msg = Sidekiq.dump_json({ 'class' => 'Bob', 'args' => [1,2], 'queue' => 'someq' })
115
+ @redis.expect :multi, [[fake_msg], 1], []
116
+ @redis.expect :rpush, 1, ['queue:someq', fake_msg]
117
+
118
+ inst = Sidekiq::Retry::Poller.new
119
+ inst.poll
120
+
121
+ @redis.verify
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+ require 'sidekiq'
3
+ require 'sidekiq/processor'
4
+
5
+ class TestStats < MiniTest::Unit::TestCase
6
+ describe 'with redis' do
7
+ before do
8
+ @redis = Sidekiq.redis = REDIS
9
+ Sidekiq.redis {|c| c.flushdb }
10
+ end
11
+
12
+ class DumbWorker
13
+ include Sidekiq::Worker
14
+
15
+ def perform(arg)
16
+ raise 'bang' if arg == nil
17
+ end
18
+ end
19
+
20
+ it 'updates global stats in the success case' do
21
+ msg = { 'class' => DumbWorker.to_s, 'args' => [""] }
22
+ boss = MiniTest::Mock.new
23
+
24
+ @redis.with do |conn|
25
+
26
+ set = conn.smembers('workers')
27
+ assert_equal 0, set.size
28
+
29
+ processor = Sidekiq::Processor.new(boss)
30
+ boss.expect(:processor_done!, nil, [processor])
31
+ boss.expect(:processor_done!, nil, [processor])
32
+ boss.expect(:processor_done!, nil, [processor])
33
+
34
+ assert_equal 0, conn.get('stat:failed').to_i
35
+ assert_equal 0, conn.get('stat:processed').to_i
36
+
37
+ processor.process(msg, 'xyzzy')
38
+ processor.process(msg, 'xyzzy')
39
+ processor.process(msg, 'xyzzy')
40
+
41
+ assert_equal 0, conn.get('stat:failed').to_i
42
+ assert_equal 3, conn.get('stat:processed').to_i
43
+ end
44
+ end
45
+
46
+ it 'updates global stats in the error case' do
47
+ msg = { 'class' => DumbWorker.to_s, 'args' => [nil] }
48
+ boss = MiniTest::Mock.new
49
+
50
+ @redis.with do |conn|
51
+ assert_equal [], conn.smembers('workers')
52
+ assert_equal 0, conn.get('stat:failed').to_i
53
+ assert_equal 0, conn.get('stat:processed').to_i
54
+
55
+ processor = Sidekiq::Processor.new(boss)
56
+
57
+ pstr = processor.to_s
58
+ assert_raises RuntimeError do
59
+ processor.process(msg, 'xyzzy')
60
+ end
61
+
62
+ assert_equal 1, conn.get('stat:failed').to_i
63
+ assert_equal 1, conn.get('stat:processed').to_i
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,97 @@
1
+ require 'helper'
2
+ require 'sidekiq'
3
+ require 'sidekiq/worker'
4
+ require 'active_record'
5
+ require 'action_mailer'
6
+ require 'sidekiq/rails'
7
+ require 'sidekiq/extensions/action_mailer'
8
+ require 'sidekiq/extensions/active_record'
9
+
10
+ Sidekiq.hook_rails!
11
+
12
+ class TestTesting < MiniTest::Unit::TestCase
13
+ describe 'sidekiq testing' do
14
+ class PerformError < RuntimeError; end
15
+
16
+ class DirectWorker
17
+ include Sidekiq::Worker
18
+ def perform(a, b)
19
+ a + b
20
+ end
21
+ end
22
+
23
+ class EnqueuedWorker
24
+ include Sidekiq::Worker
25
+ def perform(a, b)
26
+ a + b
27
+ end
28
+ end
29
+
30
+ class StoredWorker
31
+ include Sidekiq::Worker
32
+ def perform(error)
33
+ raise PerformError if error
34
+ end
35
+ end
36
+
37
+ class FooMailer < ActionMailer::Base
38
+ def bar(str)
39
+ str
40
+ end
41
+ end
42
+
43
+ class FooModel < ActiveRecord::Base
44
+ def bar(str)
45
+ str
46
+ end
47
+ end
48
+
49
+ before do
50
+ load 'sidekiq/testing.rb'
51
+ end
52
+
53
+ after do
54
+ # Undo override
55
+ Sidekiq::Worker::ClassMethods.class_eval do
56
+ remove_method :perform_async
57
+ alias_method :perform_async, :perform_async_old
58
+ remove_method :perform_async_old
59
+ end
60
+ end
61
+
62
+ it 'stubs the async call' do
63
+ assert_equal 0, DirectWorker.jobs.size
64
+ assert DirectWorker.perform_async(1, 2)
65
+ assert_equal 1, DirectWorker.jobs.size
66
+ end
67
+
68
+ it 'stubs the delay call on mailers' do
69
+ assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
70
+ FooMailer.delay.bar('hello!')
71
+ assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
72
+ end
73
+
74
+ it 'stubs the delay call on models' do
75
+ assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
76
+ FooModel.delay.bar('hello!')
77
+ assert_equal 1, Sidekiq::Extensions::DelayedModel.jobs.size
78
+ end
79
+
80
+ it 'stubs the enqueue call' do
81
+ assert_equal 0, EnqueuedWorker.jobs.size
82
+ assert Sidekiq::Client.enqueue(EnqueuedWorker, 1, 2)
83
+ assert_equal 1, EnqueuedWorker.jobs.size
84
+ end
85
+
86
+ it 'executes all stored jobs' do
87
+ assert StoredWorker.perform_async(false)
88
+ assert StoredWorker.perform_async(true)
89
+
90
+ assert_equal 2, StoredWorker.jobs.size
91
+ assert_raises PerformError do
92
+ StoredWorker.drain
93
+ end
94
+ assert_equal 0, StoredWorker.jobs.size
95
+ end
96
+ end
97
+ end