sidekiq 3.5.4 → 5.2.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq might be problematic. Click here for more details.

Files changed (175) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +61 -0
  3. data/{Contributing.md → .github/contributing.md} +0 -0
  4. data/.github/issue_template.md +11 -0
  5. data/.gitignore +3 -0
  6. data/.travis.yml +5 -10
  7. data/4.0-Upgrade.md +53 -0
  8. data/5.0-Upgrade.md +56 -0
  9. data/COMM-LICENSE +13 -11
  10. data/Changes.md +376 -1
  11. data/Ent-Changes.md +201 -2
  12. data/Gemfile +14 -18
  13. data/LICENSE +1 -1
  14. data/Pro-3.0-Upgrade.md +44 -0
  15. data/Pro-4.0-Upgrade.md +35 -0
  16. data/Pro-Changes.md +307 -2
  17. data/README.md +34 -22
  18. data/Rakefile +3 -3
  19. data/bin/sidekiq +0 -1
  20. data/bin/sidekiqctl +13 -86
  21. data/bin/sidekiqload +23 -27
  22. data/code_of_conduct.md +50 -0
  23. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +3 -3
  24. data/lib/generators/sidekiq/templates/worker_test.rb.erb +6 -6
  25. data/lib/sidekiq.rb +72 -25
  26. data/lib/sidekiq/api.rb +206 -73
  27. data/lib/sidekiq/cli.rb +145 -101
  28. data/lib/sidekiq/client.rb +42 -36
  29. data/lib/sidekiq/core_ext.rb +1 -105
  30. data/lib/sidekiq/ctl.rb +221 -0
  31. data/lib/sidekiq/delay.rb +42 -0
  32. data/lib/sidekiq/exception_handler.rb +4 -5
  33. data/lib/sidekiq/extensions/action_mailer.rb +1 -0
  34. data/lib/sidekiq/extensions/active_record.rb +1 -0
  35. data/lib/sidekiq/extensions/class_methods.rb +1 -0
  36. data/lib/sidekiq/extensions/generic_proxy.rb +8 -1
  37. data/lib/sidekiq/fetch.rb +36 -111
  38. data/lib/sidekiq/job_logger.rb +25 -0
  39. data/lib/sidekiq/job_retry.rb +262 -0
  40. data/lib/sidekiq/launcher.rb +129 -55
  41. data/lib/sidekiq/logging.rb +21 -3
  42. data/lib/sidekiq/manager.rb +83 -182
  43. data/lib/sidekiq/middleware/chain.rb +1 -0
  44. data/lib/sidekiq/middleware/i18n.rb +1 -0
  45. data/lib/sidekiq/middleware/server/active_record.rb +10 -0
  46. data/lib/sidekiq/paginator.rb +1 -0
  47. data/lib/sidekiq/processor.rb +221 -103
  48. data/lib/sidekiq/rails.rb +47 -27
  49. data/lib/sidekiq/redis_connection.rb +74 -7
  50. data/lib/sidekiq/scheduled.rb +87 -28
  51. data/lib/sidekiq/testing.rb +150 -19
  52. data/lib/sidekiq/testing/inline.rb +1 -0
  53. data/lib/sidekiq/util.rb +15 -17
  54. data/lib/sidekiq/version.rb +2 -1
  55. data/lib/sidekiq/web.rb +120 -184
  56. data/lib/sidekiq/web/action.rb +89 -0
  57. data/lib/sidekiq/web/application.rb +353 -0
  58. data/lib/sidekiq/{web_helpers.rb → web/helpers.rb} +123 -47
  59. data/lib/sidekiq/web/router.rb +100 -0
  60. data/lib/sidekiq/worker.rb +135 -18
  61. data/sidekiq.gemspec +8 -14
  62. data/web/assets/images/{status-sd8051fd480.png → status.png} +0 -0
  63. data/web/assets/javascripts/application.js +24 -20
  64. data/web/assets/javascripts/dashboard.js +33 -18
  65. data/web/assets/stylesheets/application-rtl.css +246 -0
  66. data/web/assets/stylesheets/application.css +401 -7
  67. data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
  68. data/web/assets/stylesheets/bootstrap.css +4 -8
  69. data/web/locales/ar.yml +81 -0
  70. data/web/locales/cs.yml +11 -1
  71. data/web/locales/de.yml +1 -1
  72. data/web/locales/en.yml +4 -0
  73. data/web/locales/es.yml +4 -3
  74. data/web/locales/fa.yml +80 -0
  75. data/web/locales/fr.yml +21 -12
  76. data/web/locales/he.yml +79 -0
  77. data/web/locales/ja.yml +24 -13
  78. data/web/locales/ru.yml +3 -0
  79. data/web/locales/ur.yml +80 -0
  80. data/web/views/_footer.erb +7 -9
  81. data/web/views/_job_info.erb +5 -1
  82. data/web/views/_nav.erb +5 -19
  83. data/web/views/_paging.erb +1 -1
  84. data/web/views/busy.erb +18 -9
  85. data/web/views/dashboard.erb +5 -5
  86. data/web/views/dead.erb +1 -1
  87. data/web/views/layout.erb +13 -5
  88. data/web/views/morgue.erb +16 -12
  89. data/web/views/queue.erb +12 -11
  90. data/web/views/queues.erb +5 -3
  91. data/web/views/retries.erb +19 -13
  92. data/web/views/retry.erb +2 -2
  93. data/web/views/scheduled.erb +4 -4
  94. data/web/views/scheduled_job_info.erb +1 -1
  95. metadata +45 -227
  96. data/lib/sidekiq/actor.rb +0 -39
  97. data/lib/sidekiq/middleware/server/logging.rb +0 -40
  98. data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -206
  99. data/test/config.yml +0 -9
  100. data/test/env_based_config.yml +0 -11
  101. data/test/fake_env.rb +0 -0
  102. data/test/fixtures/en.yml +0 -2
  103. data/test/helper.rb +0 -49
  104. data/test/test_api.rb +0 -493
  105. data/test/test_cli.rb +0 -335
  106. data/test/test_client.rb +0 -194
  107. data/test/test_exception_handler.rb +0 -55
  108. data/test/test_extensions.rb +0 -126
  109. data/test/test_fetch.rb +0 -104
  110. data/test/test_logging.rb +0 -34
  111. data/test/test_manager.rb +0 -168
  112. data/test/test_middleware.rb +0 -159
  113. data/test/test_processor.rb +0 -237
  114. data/test/test_rails.rb +0 -21
  115. data/test/test_redis_connection.rb +0 -126
  116. data/test/test_retry.rb +0 -325
  117. data/test/test_scheduled.rb +0 -114
  118. data/test/test_scheduling.rb +0 -49
  119. data/test/test_sidekiq.rb +0 -99
  120. data/test/test_testing.rb +0 -142
  121. data/test/test_testing_fake.rb +0 -268
  122. data/test/test_testing_inline.rb +0 -93
  123. data/test/test_util.rb +0 -16
  124. data/test/test_web.rb +0 -608
  125. data/test/test_web_helpers.rb +0 -53
  126. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  127. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  128. data/web/assets/images/status/active.png +0 -0
  129. data/web/assets/images/status/idle.png +0 -0
  130. data/web/assets/javascripts/locales/README.md +0 -27
  131. data/web/assets/javascripts/locales/jquery.timeago.ar.js +0 -96
  132. data/web/assets/javascripts/locales/jquery.timeago.bg.js +0 -18
  133. data/web/assets/javascripts/locales/jquery.timeago.bs.js +0 -49
  134. data/web/assets/javascripts/locales/jquery.timeago.ca.js +0 -18
  135. data/web/assets/javascripts/locales/jquery.timeago.cs.js +0 -18
  136. data/web/assets/javascripts/locales/jquery.timeago.cy.js +0 -20
  137. data/web/assets/javascripts/locales/jquery.timeago.da.js +0 -18
  138. data/web/assets/javascripts/locales/jquery.timeago.de.js +0 -18
  139. data/web/assets/javascripts/locales/jquery.timeago.el.js +0 -18
  140. data/web/assets/javascripts/locales/jquery.timeago.en-short.js +0 -20
  141. data/web/assets/javascripts/locales/jquery.timeago.en.js +0 -20
  142. data/web/assets/javascripts/locales/jquery.timeago.es.js +0 -18
  143. data/web/assets/javascripts/locales/jquery.timeago.et.js +0 -18
  144. data/web/assets/javascripts/locales/jquery.timeago.fa.js +0 -22
  145. data/web/assets/javascripts/locales/jquery.timeago.fi.js +0 -28
  146. data/web/assets/javascripts/locales/jquery.timeago.fr-short.js +0 -16
  147. data/web/assets/javascripts/locales/jquery.timeago.fr.js +0 -17
  148. data/web/assets/javascripts/locales/jquery.timeago.he.js +0 -18
  149. data/web/assets/javascripts/locales/jquery.timeago.hr.js +0 -49
  150. data/web/assets/javascripts/locales/jquery.timeago.hu.js +0 -18
  151. data/web/assets/javascripts/locales/jquery.timeago.hy.js +0 -18
  152. data/web/assets/javascripts/locales/jquery.timeago.id.js +0 -18
  153. data/web/assets/javascripts/locales/jquery.timeago.it.js +0 -16
  154. data/web/assets/javascripts/locales/jquery.timeago.ja.js +0 -19
  155. data/web/assets/javascripts/locales/jquery.timeago.ko.js +0 -17
  156. data/web/assets/javascripts/locales/jquery.timeago.lt.js +0 -20
  157. data/web/assets/javascripts/locales/jquery.timeago.mk.js +0 -20
  158. data/web/assets/javascripts/locales/jquery.timeago.nl.js +0 -20
  159. data/web/assets/javascripts/locales/jquery.timeago.no.js +0 -18
  160. data/web/assets/javascripts/locales/jquery.timeago.pl.js +0 -31
  161. data/web/assets/javascripts/locales/jquery.timeago.pt-br.js +0 -16
  162. data/web/assets/javascripts/locales/jquery.timeago.pt.js +0 -16
  163. data/web/assets/javascripts/locales/jquery.timeago.ro.js +0 -18
  164. data/web/assets/javascripts/locales/jquery.timeago.rs.js +0 -49
  165. data/web/assets/javascripts/locales/jquery.timeago.ru.js +0 -34
  166. data/web/assets/javascripts/locales/jquery.timeago.sk.js +0 -18
  167. data/web/assets/javascripts/locales/jquery.timeago.sl.js +0 -44
  168. data/web/assets/javascripts/locales/jquery.timeago.sv.js +0 -18
  169. data/web/assets/javascripts/locales/jquery.timeago.th.js +0 -20
  170. data/web/assets/javascripts/locales/jquery.timeago.tr.js +0 -16
  171. data/web/assets/javascripts/locales/jquery.timeago.uk.js +0 -34
  172. data/web/assets/javascripts/locales/jquery.timeago.uz.js +0 -19
  173. data/web/assets/javascripts/locales/jquery.timeago.zh-cn.js +0 -20
  174. data/web/assets/javascripts/locales/jquery.timeago.zh-tw.js +0 -20
  175. data/web/views/_poll_js.erb +0 -5
@@ -1,159 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/middleware/chain'
3
- require 'sidekiq/processor'
4
-
5
- class TestMiddleware < Sidekiq::Test
6
- describe 'middleware chain' do
7
- before do
8
- $errors = []
9
- Sidekiq.redis = REDIS
10
- end
11
-
12
- class CustomMiddleware
13
- def initialize(name, recorder)
14
- @name = name
15
- @recorder = recorder
16
- end
17
-
18
- def call(*args)
19
- @recorder << [@name, 'before']
20
- yield
21
- @recorder << [@name, 'after']
22
- end
23
- end
24
-
25
- it 'supports custom middleware' do
26
- chain = Sidekiq::Middleware::Chain.new
27
- chain.add CustomMiddleware, 1, []
28
-
29
- assert_equal CustomMiddleware, chain.entries.last.klass
30
- end
31
-
32
- class CustomWorker
33
- $recorder = []
34
- include Sidekiq::Worker
35
- def perform(recorder)
36
- $recorder << ['work_performed']
37
- end
38
- end
39
-
40
- class NonYieldingMiddleware
41
- def call(*args)
42
- end
43
- end
44
-
45
- class AnotherCustomMiddleware
46
- def initialize(name, recorder)
47
- @name = name
48
- @recorder = recorder
49
- end
50
-
51
- def call(*args)
52
- @recorder << [@name, 'before']
53
- yield
54
- @recorder << [@name, 'after']
55
- end
56
- end
57
-
58
- class YetAnotherCustomMiddleware
59
- def initialize(name, recorder)
60
- @name = name
61
- @recorder = recorder
62
- end
63
-
64
- def call(*args)
65
- @recorder << [@name, 'before']
66
- yield
67
- @recorder << [@name, 'after']
68
- end
69
- end
70
-
71
- it 'executes middleware in the proper order' do
72
- msg = Sidekiq.dump_json({ 'class' => CustomWorker.to_s, 'args' => [$recorder] })
73
-
74
- Sidekiq.server_middleware do |chain|
75
- # should only add once, second should replace the first
76
- 2.times { |i| chain.add CustomMiddleware, i.to_s, $recorder }
77
- chain.insert_before CustomMiddleware, AnotherCustomMiddleware, '2', $recorder
78
- chain.insert_after AnotherCustomMiddleware, YetAnotherCustomMiddleware, '3', $recorder
79
- end
80
-
81
- boss = Minitest::Mock.new
82
- processor = Sidekiq::Processor.new(boss)
83
- actor = Minitest::Mock.new
84
- actor.expect(:processor_done, nil, [processor])
85
- actor.expect(:real_thread, nil, [nil, Thread])
86
- boss.expect(:async, actor, [])
87
- boss.expect(:async, actor, [])
88
- processor.process(Sidekiq::BasicFetch::UnitOfWork.new('queue:default', msg))
89
- assert_equal %w(2 before 3 before 1 before work_performed 1 after 3 after 2 after), $recorder.flatten
90
- end
91
-
92
- it 'correctly replaces middleware when using middleware with options in the initializer' do
93
- chain = Sidekiq::Middleware::Chain.new
94
- chain.add Sidekiq::Middleware::Server::RetryJobs
95
- chain.add Sidekiq::Middleware::Server::RetryJobs, {:max_retries => 5}
96
- assert_equal 1, chain.count
97
- end
98
-
99
- it 'correctly prepends middleware' do
100
- chain = Sidekiq::Middleware::Chain.new
101
- chain_entries = chain.entries
102
- chain.add CustomMiddleware
103
- chain.prepend YetAnotherCustomMiddleware
104
- assert_equal YetAnotherCustomMiddleware, chain_entries.first.klass
105
- assert_equal CustomMiddleware, chain_entries.last.klass
106
- end
107
-
108
- it 'allows middleware to abruptly stop processing rest of chain' do
109
- recorder = []
110
- chain = Sidekiq::Middleware::Chain.new
111
- chain.add NonYieldingMiddleware
112
- chain.add CustomMiddleware, 1, recorder
113
-
114
- final_action = nil
115
- chain.invoke { final_action = true }
116
- assert_equal nil, final_action
117
- assert_equal [], recorder
118
- end
119
- end
120
-
121
- describe 'i18n' do
122
- before do
123
- require 'i18n'
124
- I18n.enforce_available_locales = false
125
- require 'sidekiq/middleware/i18n'
126
- end
127
-
128
- it 'saves and restores locale' do
129
- I18n.locale = 'fr'
130
- msg = {}
131
- mw = Sidekiq::Middleware::I18n::Client.new
132
- mw.call(nil, msg, nil, nil) { }
133
- assert_equal :fr, msg['locale']
134
-
135
- msg['locale'] = 'jp'
136
- I18n.locale = I18n.default_locale
137
- assert_equal :en, I18n.locale
138
- mw = Sidekiq::Middleware::I18n::Server.new
139
- mw.call(nil, msg, nil) do
140
- assert_equal :jp, I18n.locale
141
- end
142
- assert_equal :en, I18n.locale
143
- end
144
-
145
- it 'supports I18n.enforce_available_locales = true' do
146
- I18n.enforce_available_locales = true
147
- I18n.available_locales = [:en, :jp]
148
-
149
- msg = { 'locale' => 'jp' }
150
- mw = Sidekiq::Middleware::I18n::Server.new
151
- mw.call(nil, msg, nil) do
152
- assert_equal :jp, I18n.locale
153
- end
154
-
155
- I18n.enforce_available_locales = false
156
- I18n.available_locales = nil
157
- end
158
- end
159
- end
@@ -1,237 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/processor'
3
-
4
- class TestProcessor < Sidekiq::Test
5
- TestException = Class.new(StandardError)
6
- TEST_EXCEPTION = TestException.new("kerboom!")
7
-
8
- describe 'with mock setup' do
9
- before do
10
- $invokes = 0
11
- @boss = Minitest::Mock.new
12
- @processor = ::Sidekiq::Processor.new(@boss)
13
- end
14
-
15
- class MockWorker
16
- include Sidekiq::Worker
17
- def perform(args)
18
- raise TEST_EXCEPTION if args == 'boom'
19
- args.pop if args.is_a? Array
20
- $invokes += 1
21
- end
22
- end
23
-
24
- def work(msg, queue='queue:default')
25
- Sidekiq::BasicFetch::UnitOfWork.new(queue, msg)
26
- end
27
-
28
- it 'processes as expected' do
29
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
30
- actor = Minitest::Mock.new
31
- actor.expect(:processor_done, nil, [@processor])
32
- actor.expect(:real_thread, nil, [nil, Thread])
33
- @boss.expect(:async, actor, [])
34
- @boss.expect(:async, actor, [])
35
- @processor.process(work(msg))
36
- @boss.verify
37
- assert_equal 1, $invokes
38
- end
39
-
40
- it 'executes a worker as expected' do
41
- worker = Minitest::Mock.new
42
- worker.expect(:perform, nil, [1, 2, 3])
43
- @processor.execute_job(worker, [1, 2, 3])
44
- end
45
-
46
- it 'passes exceptions to ExceptionHandler' do
47
- actor = Minitest::Mock.new
48
- actor.expect(:real_thread, nil, [nil, Thread])
49
- @boss.expect(:async, actor, [])
50
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
51
- begin
52
- @processor.process(work(msg))
53
- flunk "Expected #process to raise exception"
54
- rescue TestException
55
- end
56
-
57
- assert_equal 0, $invokes
58
- end
59
-
60
- it 're-raises exceptions after handling' do
61
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
62
- re_raise = false
63
- actor = Minitest::Mock.new
64
- actor.expect(:real_thread, nil, [nil, Thread])
65
- @boss.expect(:async, actor, [])
66
-
67
- begin
68
- @processor.process(work(msg))
69
- rescue TestException
70
- re_raise = true
71
- end
72
-
73
- assert re_raise, "does not re-raise exceptions after handling"
74
- end
75
-
76
- it 'does not modify original arguments' do
77
- msg = { 'class' => MockWorker.to_s, 'args' => [['myarg']] }
78
- msgstr = Sidekiq.dump_json(msg)
79
- processor = ::Sidekiq::Processor.new(@boss)
80
- actor = Minitest::Mock.new
81
- actor.expect(:processor_done, nil, [processor])
82
- actor.expect(:real_thread, nil, [nil, Thread])
83
- @boss.expect(:async, actor, [])
84
- @boss.expect(:async, actor, [])
85
- processor.process(work(msgstr))
86
- assert_equal [['myarg']], msg['args']
87
- end
88
-
89
- describe 'acknowledgement' do
90
- class ExceptionRaisingMiddleware
91
- def initialize(raise_before_yield, raise_after_yield, skip)
92
- @raise_before_yield = raise_before_yield
93
- @raise_after_yield = raise_after_yield
94
- @skip = skip
95
- end
96
-
97
- def call(worker, item, queue)
98
- raise TEST_EXCEPTION if @raise_before_yield
99
- yield unless @skip
100
- raise TEST_EXCEPTION if @raise_after_yield
101
- end
102
- end
103
-
104
- let(:raise_before_yield) { false }
105
- let(:raise_after_yield) { false }
106
- let(:skip_job) { false }
107
- let(:worker_args) { ['myarg'] }
108
- let(:work) { MiniTest::Mock.new }
109
- let(:actor) { Minitest::Mock.new }
110
-
111
- before do
112
- work.expect(:queue_name, 'queues:default')
113
- work.expect(:message, Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => worker_args }))
114
- Sidekiq.server_middleware do |chain|
115
- chain.prepend ExceptionRaisingMiddleware, raise_before_yield, raise_after_yield, skip_job
116
- end
117
-
118
- actor.expect(:real_thread, nil, [nil, Thread])
119
- @boss.expect(:async, actor, [])
120
- end
121
-
122
- after do
123
- Sidekiq.server_middleware do |chain|
124
- chain.remove ExceptionRaisingMiddleware
125
- end
126
- work.verify
127
- end
128
-
129
- describe 'middleware throws an exception before processing the work' do
130
- let(:raise_before_yield) { true }
131
-
132
- it 'does not ack' do
133
- begin
134
- @processor.process(work)
135
- flunk "Expected #process to raise exception"
136
- rescue TestException
137
- end
138
- end
139
- end
140
-
141
- describe 'middleware throws an exception after processing the work' do
142
- let(:raise_after_yield) { true }
143
-
144
- it 'acks the job' do
145
- work.expect(:acknowledge, nil)
146
- begin
147
- @processor.process(work)
148
- flunk "Expected #process to raise exception"
149
- rescue TestException
150
- end
151
- end
152
- end
153
-
154
- describe 'middleware decides to skip work' do
155
- let(:skip_job) { true }
156
-
157
- it 'acks the job' do
158
- work.expect(:acknowledge, nil)
159
- @boss.expect(:async, actor, [])
160
- actor.expect(:processor_done, nil, [@processor])
161
- @processor.process(work)
162
- end
163
- end
164
-
165
- describe 'worker raises an exception' do
166
- let(:worker_args) { ['boom'] }
167
-
168
- it 'acks the job' do
169
- work.expect(:acknowledge, nil)
170
- begin
171
- @processor.process(work)
172
- flunk "Expected #process to raise exception"
173
- rescue TestException
174
- end
175
- end
176
- end
177
-
178
- describe 'everything goes well' do
179
- it 'acks the job' do
180
- work.expect(:acknowledge, nil)
181
- @boss.expect(:async, actor, [])
182
- actor.expect(:processor_done, nil, [@processor])
183
- @processor.process(work)
184
- end
185
- end
186
- end
187
-
188
- describe 'stats' do
189
- before do
190
- Sidekiq.redis {|c| c.flushdb }
191
- end
192
-
193
- describe 'when successful' do
194
- let(:processed_today_key) { "stat:processed:#{Time.now.utc.strftime("%Y-%m-%d")}" }
195
-
196
- def successful_job
197
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['myarg'] })
198
- actor = Minitest::Mock.new
199
- actor.expect(:real_thread, nil, [nil, Thread])
200
- actor.expect(:processor_done, nil, [@processor])
201
- @boss.expect(:async, actor, [])
202
- @boss.expect(:async, actor, [])
203
- @processor.process(work(msg))
204
- end
205
-
206
- it 'increments processed stat' do
207
- assert_equal 0, Sidekiq::Stats.new.processed
208
- successful_job
209
- assert_equal 1, Sidekiq::Stats.new.processed
210
- assert_equal Sidekiq::Processor::STATS_TIMEOUT, Sidekiq.redis { |conn| conn.ttl(processed_today_key) }
211
- end
212
- end
213
-
214
- describe 'when failed' do
215
- let(:failed_today_key) { "stat:failed:#{Time.now.utc.strftime("%Y-%m-%d")}" }
216
-
217
- def failed_job
218
- actor = Minitest::Mock.new
219
- actor.expect(:real_thread, nil, [nil, Thread])
220
- @boss.expect(:async, actor, [])
221
- msg = Sidekiq.dump_json({ 'class' => MockWorker.to_s, 'args' => ['boom'] })
222
- begin
223
- @processor.process(work(msg))
224
- rescue TestException
225
- end
226
- end
227
-
228
- it 'increments failed stat' do
229
- assert_equal 0, Sidekiq::Stats.new.failed
230
- failed_job
231
- assert_equal 1, Sidekiq::Stats.new.failed
232
- assert_equal Sidekiq::Processor::STATS_TIMEOUT, Sidekiq.redis { |conn| conn.ttl(failed_today_key) }
233
- end
234
- end
235
- end
236
- end
237
- end
@@ -1,21 +0,0 @@
1
- require_relative 'helper'
2
-
3
- $HAS_AJ = true
4
- begin
5
- require 'active_job'
6
- rescue LoadError
7
- $HAS_AJ = false
8
- end
9
-
10
- class TestRails < Sidekiq::Test
11
-
12
- describe 'ActiveJob' do
13
- it 'does not allow Sidekiq::Worker in AJ::Base classes' do
14
- ex = assert_raises ArgumentError do
15
- c = Class.new(ActiveJob::Base)
16
- c.send(:include, Sidekiq::Worker)
17
- end
18
- assert_includes ex.message, "cannot include"
19
- end if $HAS_AJ
20
- end
21
- end
@@ -1,126 +0,0 @@
1
- require_relative 'helper'
2
-
3
- class TestRedisConnection < Sidekiq::Test
4
-
5
- describe ".create" do
6
-
7
- it "creates a pooled redis connection" do
8
- pool = Sidekiq::RedisConnection.create
9
- assert_equal Redis, pool.checkout.class
10
- end
11
-
12
- describe "network_timeout" do
13
- it "sets a custom network_timeout if specified" do
14
- pool = Sidekiq::RedisConnection.create(:network_timeout => 8)
15
- redis = pool.checkout
16
-
17
- assert_equal 8, redis.client.timeout
18
- end
19
-
20
- it "uses the default network_timeout if none specified" do
21
- pool = Sidekiq::RedisConnection.create
22
- redis = pool.checkout
23
-
24
- assert_equal 5, redis.client.timeout
25
- end
26
- end
27
-
28
- describe "namespace" do
29
- it "uses a given :namespace" do
30
- pool = Sidekiq::RedisConnection.create(:namespace => "xxx")
31
- assert_equal "xxx", pool.checkout.namespace
32
- end
33
-
34
- it "uses given :namespace over :namespace from Sidekiq.options" do
35
- Sidekiq.options[:namespace] = "xxx"
36
- pool = Sidekiq::RedisConnection.create(:namespace => "yyy")
37
- assert_equal "yyy", pool.checkout.namespace
38
- end
39
- end
40
-
41
- describe "socket path" do
42
- it "uses a given :path" do
43
- pool = Sidekiq::RedisConnection.create(:path => "/var/run/redis.sock")
44
- assert_equal "unix", pool.checkout.client.scheme
45
- assert_equal "redis:///var/run/redis.sock/0", pool.checkout.client.id
46
- end
47
-
48
- it "uses a given :path and :db" do
49
- pool = Sidekiq::RedisConnection.create(:path => "/var/run/redis.sock", :db => 8)
50
- assert_equal "unix", pool.checkout.client.scheme
51
- assert_equal "redis:///var/run/redis.sock/8", pool.checkout.client.id
52
- end
53
- end
54
-
55
- describe "pool_timeout" do
56
- it "uses a given :timeout over the default of 1" do
57
- pool = Sidekiq::RedisConnection.create(:pool_timeout => 5)
58
-
59
- assert_equal 5, pool.instance_eval{ @timeout }
60
- end
61
-
62
- it "uses the default timeout of 1 if no override" do
63
- pool = Sidekiq::RedisConnection.create
64
-
65
- assert_equal 1, pool.instance_eval{ @timeout }
66
- end
67
- end
68
- end
69
-
70
- describe ".determine_redis_provider" do
71
-
72
- before do
73
- @old_env = ENV.to_hash
74
- end
75
-
76
- after do
77
- ENV.update(@old_env)
78
- end
79
-
80
- def with_env_var(var, uri, skip_provider=false)
81
- vars = ['REDISTOGO_URL', 'REDIS_PROVIDER', 'REDIS_URL'] - [var]
82
- vars.each do |v|
83
- next if skip_provider
84
- ENV[v] = nil
85
- end
86
- ENV[var] = uri
87
- assert_equal uri, Sidekiq::RedisConnection.__send__(:determine_redis_provider)
88
- ENV[var] = nil
89
- end
90
-
91
- describe "with REDISTOGO_URL and a parallel REDIS_PROVIDER set" do
92
- it "sets connection URI to the provider" do
93
- uri = 'redis://sidekiq-redis-provider:6379/0'
94
- provider = 'SIDEKIQ_REDIS_PROVIDER'
95
-
96
- ENV['REDIS_PROVIDER'] = provider
97
- ENV[provider] = uri
98
- ENV['REDISTOGO_URL'] = 'redis://redis-to-go:6379/0'
99
- with_env_var provider, uri, true
100
-
101
- ENV[provider] = nil
102
- end
103
- end
104
-
105
- describe "with REDIS_PROVIDER set" do
106
- it "sets connection URI to the provider" do
107
- uri = 'redis://sidekiq-redis-provider:6379/0'
108
- provider = 'SIDEKIQ_REDIS_PROVIDER'
109
-
110
- ENV['REDIS_PROVIDER'] = provider
111
- ENV[provider] = uri
112
-
113
- with_env_var provider, uri, true
114
-
115
- ENV[provider] = nil
116
- end
117
- end
118
-
119
- describe "with REDIS_URL set" do
120
- it "sets connection URI to custom uri" do
121
- with_env_var 'REDIS_URL', 'redis://redis-uri:6379/0'
122
- end
123
- end
124
-
125
- end
126
- end