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,335 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/cli'
3
- require 'tempfile'
4
-
5
- class Sidekiq::CLI
6
- def die(code)
7
- @code = code
8
- end
9
-
10
- def valid?
11
- !@code
12
- end
13
- end
14
-
15
- class TestCli < Sidekiq::Test
16
- describe 'CLI#parse' do
17
-
18
- before do
19
- @cli = Sidekiq::CLI.new
20
- @opts = Sidekiq.options.dup
21
- end
22
-
23
- after do
24
- Sidekiq.options = @opts
25
- end
26
-
27
- it 'does not require the specified Ruby code' do
28
- @cli.parse(['sidekiq', '-r', './test/fake_env.rb'])
29
- refute($LOADED_FEATURES.any? { |x| x =~ /fake_env/ })
30
- assert @cli.valid?
31
- end
32
-
33
- it 'does not boot rails' do
34
- refute defined?(::Rails::Application)
35
- @cli.parse(['sidekiq', '-r', './myapp'])
36
- refute defined?(::Rails::Application)
37
- end
38
-
39
- it 'changes concurrency' do
40
- @cli.parse(['sidekiq', '-c', '60', '-r', './test/fake_env.rb'])
41
- assert_equal 60, Sidekiq.options[:concurrency]
42
- end
43
-
44
- it 'changes queues' do
45
- @cli.parse(['sidekiq', '-q', 'foo', '-r', './test/fake_env.rb'])
46
- assert_equal ['foo'], Sidekiq.options[:queues]
47
- end
48
-
49
- it 'accepts a process index' do
50
- @cli.parse(['sidekiq', '-i', '7', '-r', './test/fake_env.rb'])
51
- assert_equal 7, Sidekiq.options[:index]
52
- end
53
-
54
- it 'accepts a stringy process index' do
55
- @cli.parse(['sidekiq', '-i', 'worker.7', '-r', './test/fake_env.rb'])
56
- assert_equal 7, Sidekiq.options[:index]
57
- end
58
-
59
- it 'sets strictly ordered queues if weights are not present' do
60
- @cli.parse(['sidekiq', '-q', 'foo', '-q', 'bar', '-r', './test/fake_env.rb'])
61
- assert_equal true, !!Sidekiq.options[:strict]
62
- end
63
-
64
- it 'does not set strictly ordered queues if weights are present' do
65
- @cli.parse(['sidekiq', '-q', 'foo,3', '-r', './test/fake_env.rb'])
66
- assert_equal false, !!Sidekiq.options[:strict]
67
- end
68
-
69
- it 'does not set strictly ordered queues if weights are present with multiple queues' do
70
- @cli.parse(['sidekiq', '-q', 'foo,3', '-q', 'bar', '-r', './test/fake_env.rb'])
71
- assert_equal false, !!Sidekiq.options[:strict]
72
- end
73
-
74
- it 'changes timeout' do
75
- @cli.parse(['sidekiq', '-t', '30', '-r', './test/fake_env.rb'])
76
- assert_equal 30, Sidekiq.options[:timeout]
77
- end
78
-
79
- it 'handles multiple queues with weights' do
80
- @cli.parse(['sidekiq', '-q', 'foo,3', '-q', 'bar', '-r', './test/fake_env.rb'])
81
- assert_equal %w(foo foo foo bar), Sidekiq.options[:queues]
82
- end
83
-
84
- it 'handles queues with multi-word names' do
85
- @cli.parse(['sidekiq', '-q', 'queue_one', '-q', 'queue-two', '-r', './test/fake_env.rb'])
86
- assert_equal %w(queue_one queue-two), Sidekiq.options[:queues]
87
- end
88
-
89
- it 'handles queues with dots in the name' do
90
- @cli.parse(['sidekiq', '-q', 'foo.bar', '-r', './test/fake_env.rb'])
91
- assert_equal ['foo.bar'], Sidekiq.options[:queues]
92
- end
93
-
94
- it 'sets verbose' do
95
- old = Sidekiq.logger.level
96
- @cli.parse(['sidekiq', '-v', '-r', './test/fake_env.rb'])
97
- assert_equal Logger::DEBUG, Sidekiq.logger.level
98
- # If we leave the logger at DEBUG it'll add a lot of noise to the test output
99
- Sidekiq.options.delete(:verbose)
100
- Sidekiq.logger.level = old
101
- end
102
-
103
- describe 'with logfile' do
104
- before do
105
- @old_logger = Sidekiq.logger
106
- @tmp_log_path = '/tmp/sidekiq.log'
107
- end
108
-
109
- after do
110
- Sidekiq.logger = @old_logger
111
- Sidekiq.options.delete(:logfile)
112
- File.unlink @tmp_log_path if File.exist?(@tmp_log_path)
113
- end
114
-
115
- it 'sets the logfile path' do
116
- @cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
117
-
118
- assert_equal @tmp_log_path, Sidekiq.options[:logfile]
119
- end
120
-
121
- it 'creates and writes to a logfile' do
122
- @cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
123
-
124
- Sidekiq.logger.info('test message')
125
-
126
- assert_match(/test message/, File.read(@tmp_log_path), "didn't include the log message")
127
- end
128
-
129
- it 'appends messages to a logfile' do
130
- File.open(@tmp_log_path, 'w') do |f|
131
- f.puts 'already existent log message'
132
- end
133
-
134
- @cli.parse(['sidekiq', '-L', @tmp_log_path, '-r', './test/fake_env.rb'])
135
-
136
- Sidekiq.logger.info('test message')
137
-
138
- log_file_content = File.read(@tmp_log_path)
139
- assert_match(/already existent/, log_file_content, "didn't include the old message")
140
- assert_match(/test message/, log_file_content, "didn't include the new message")
141
- end
142
- end
143
-
144
- describe 'with pidfile' do
145
- before do
146
- @tmp_file = Tempfile.new('sidekiq-test')
147
- @tmp_path = @tmp_file.path
148
- @tmp_file.close!
149
-
150
- @cli.parse(['sidekiq', '-P', @tmp_path, '-r', './test/fake_env.rb'])
151
- end
152
-
153
- after do
154
- File.unlink @tmp_path if File.exist? @tmp_path
155
- end
156
-
157
- it 'sets pidfile path' do
158
- assert_equal @tmp_path, Sidekiq.options[:pidfile]
159
- end
160
-
161
- it 'writes pidfile' do
162
- assert_equal File.read(@tmp_path).strip.to_i, Process.pid
163
- end
164
- end
165
-
166
- describe 'with config file' do
167
- before do
168
- @cli.parse(['sidekiq', '-C', './test/config.yml'])
169
- end
170
-
171
- it 'parses as expected' do
172
- assert_equal './test/config.yml', Sidekiq.options[:config_file]
173
- refute Sidekiq.options[:verbose]
174
- assert_equal './test/fake_env.rb', Sidekiq.options[:require]
175
- assert_equal nil, Sidekiq.options[:environment]
176
- assert_equal 50, Sidekiq.options[:concurrency]
177
- assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
178
- assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
179
- assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
180
- assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
181
- end
182
- end
183
-
184
- describe 'with env based config file' do
185
- before do
186
- @cli.parse(['sidekiq', '-e', 'staging', '-C', './test/env_based_config.yml'])
187
- end
188
-
189
- it 'parses as expected' do
190
- assert_equal './test/env_based_config.yml', Sidekiq.options[:config_file]
191
- refute Sidekiq.options[:verbose]
192
- assert_equal './test/fake_env.rb', Sidekiq.options[:require]
193
- assert_equal 'staging', Sidekiq.options[:environment]
194
- assert_equal 5, Sidekiq.options[:concurrency]
195
- assert_equal '/tmp/sidekiq-config-test.pid', Sidekiq.options[:pidfile]
196
- assert_equal '/tmp/sidekiq.log', Sidekiq.options[:logfile]
197
- assert_equal 2, Sidekiq.options[:queues].count { |q| q == 'very_often' }
198
- assert_equal 1, Sidekiq.options[:queues].count { |q| q == 'seldom' }
199
- end
200
- end
201
-
202
- describe 'with an empty config file' do
203
- before do
204
- @tmp_file = Tempfile.new('sidekiq-test')
205
- @tmp_path = @tmp_file.path
206
- @tmp_file.close!
207
- end
208
-
209
- after do
210
- File.unlink @tmp_path if File.exist? @tmp_path
211
- end
212
-
213
- it 'takes a path' do
214
- @cli.parse(['sidekiq', '-C', @tmp_path])
215
- assert_equal @tmp_path, Sidekiq.options[:config_file]
216
- end
217
-
218
- it 'should have an identical options hash, except for config_file' do
219
- @cli.parse(['sidekiq'])
220
- old_options = Sidekiq.options.clone
221
-
222
- @cli.parse(['sidekiq', '-C', @tmp_path])
223
- new_options = Sidekiq.options.clone
224
- refute_equal old_options, new_options
225
-
226
- new_options.delete(:config_file)
227
- assert_equal old_options, new_options
228
- end
229
- end
230
-
231
- describe 'with config file and flags' do
232
- before do
233
- # We need an actual file here.
234
- @tmp_lib_path = '/tmp/require-me.rb'
235
- File.open(@tmp_lib_path, 'w') do |f|
236
- f.puts "# do work"
237
- end
238
-
239
- @tmp_file = Tempfile.new('sidekiqr')
240
- @tmp_path = @tmp_file.path
241
- @tmp_file.close!
242
-
243
- @cli.parse(['sidekiq',
244
- '-C', './test/config.yml',
245
- '-e', 'snoop',
246
- '-c', '100',
247
- '-r', @tmp_lib_path,
248
- '-P', @tmp_path,
249
- '-q', 'often,7',
250
- '-q', 'seldom,3'])
251
- end
252
-
253
- after do
254
- File.unlink @tmp_lib_path if File.exist? @tmp_lib_path
255
- File.unlink @tmp_path if File.exist? @tmp_path
256
- end
257
-
258
- it 'gives the expected options' do
259
- assert_equal 100, Sidekiq.options[:concurrency]
260
- assert_equal @tmp_lib_path, Sidekiq.options[:require]
261
- assert_equal 'snoop', Sidekiq.options[:environment]
262
- assert_equal @tmp_path, Sidekiq.options[:pidfile]
263
- assert_equal 7, Sidekiq.options[:queues].count { |q| q == 'often' }
264
- assert_equal 3, Sidekiq.options[:queues].count { |q| q == 'seldom' }
265
- end
266
- end
267
-
268
- describe 'Sidekiq::CLI#parse_queues' do
269
- describe 'when weight is present' do
270
- it 'concatenates queues by factor of weight and sets strict to false' do
271
- opts = { strict: true }
272
- @cli.__send__ :parse_queues, opts, [['often', 7], ['repeatedly', 3]]
273
- @cli.__send__ :parse_queues, opts, [['once']]
274
- assert_equal (%w[often] * 7 + %w[repeatedly] * 3 + %w[once]), opts[:queues]
275
- assert !opts[:strict]
276
- end
277
- end
278
-
279
- describe 'when weight is not present' do
280
- it 'returns queues and sets strict' do
281
- opts = { strict: true }
282
- @cli.__send__ :parse_queues, opts, [['once'], ['one_time']]
283
- @cli.__send__ :parse_queues, opts, [['einmal']]
284
- assert_equal %w[once one_time einmal], opts[:queues]
285
- assert opts[:strict]
286
- end
287
- end
288
- end
289
-
290
- describe 'Sidekiq::CLI#parse_queue' do
291
- describe 'when weight is present' do
292
- it 'concatenates queue to opts[:queues] weight number of times and sets strict to false' do
293
- opts = { strict: true }
294
- @cli.__send__ :parse_queue, opts, 'often', 7
295
- assert_equal %w[often] * 7, opts[:queues]
296
- assert !opts[:strict]
297
- end
298
- end
299
-
300
- describe 'when weight is not present' do
301
- it 'concatenates queue to opts[:queues] once and leaves strict true' do
302
- opts = { strict: true }
303
- @cli.__send__ :parse_queue, opts, 'once', nil
304
- assert_equal %w[once], opts[:queues]
305
- assert opts[:strict]
306
- end
307
- end
308
- end
309
- end
310
-
311
- describe 'misc' do
312
- it 'handles interrupts' do
313
- cli = Sidekiq::CLI.new
314
- assert_raises Interrupt do
315
- cli.handle_signal('INT')
316
- end
317
- assert_raises Interrupt do
318
- cli.handle_signal('TERM')
319
- end
320
- cli.handle_signal('USR2')
321
- cli.handle_signal('TTIN')
322
- end
323
-
324
- it 'can fire events' do
325
- count = 0
326
- Sidekiq.options[:lifecycle_events][:startup] = [proc {
327
- count += 1
328
- }]
329
- cli = Sidekiq::CLI.new
330
- cli.fire_event(:startup)
331
- assert_equal 1, count
332
- end
333
- end
334
-
335
- end
@@ -1,194 +0,0 @@
1
- require_relative 'helper'
2
-
3
- class TestClient < Sidekiq::Test
4
- describe 'errors' do
5
- it 'raises ArgumentError with invalid params' do
6
- assert_raises ArgumentError do
7
- Sidekiq::Client.push('foo', 1)
8
- end
9
-
10
- assert_raises ArgumentError do
11
- Sidekiq::Client.push('foo', :class => 'Foo', :noargs => [1, 2])
12
- end
13
-
14
- assert_raises ArgumentError do
15
- Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'noargs' => [1, 2])
16
- end
17
-
18
- assert_raises ArgumentError do
19
- Sidekiq::Client.push('queue' => 'foo', 'class' => 42, 'args' => [1, 2])
20
- end
21
-
22
- assert_raises ArgumentError do
23
- Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => 1)
24
- end
25
- end
26
- end
27
-
28
- describe 'as instance' do
29
- it 'can push' do
30
- client = Sidekiq::Client.new
31
- jid = client.push('class' => 'Blah', 'args' => [1,2,3])
32
- assert_equal 24, jid.size
33
- end
34
-
35
- it 'allows local middleware modification' do
36
- $called = false
37
- mware = Class.new { def call(worker_klass,msg,q,r); $called = true; msg;end }
38
- client = Sidekiq::Client.new
39
- client.middleware do |chain|
40
- chain.add mware
41
- end
42
- client.push('class' => 'Blah', 'args' => [1,2,3])
43
-
44
- assert $called
45
- assert client.middleware.exists?(mware)
46
- refute Sidekiq.client_middleware.exists?(mware)
47
- end
48
- end
49
-
50
- describe 'client' do
51
- it 'pushes messages to redis' do
52
- q = Sidekiq::Queue.new('foo')
53
- pre = q.size
54
- jid = Sidekiq::Client.push('queue' => 'foo', 'class' => MyWorker, 'args' => [1, 2])
55
- assert jid
56
- assert_equal 24, jid.size
57
- assert_equal pre + 1, q.size
58
- end
59
-
60
- it 'pushes messages to redis using a String class' do
61
- q = Sidekiq::Queue.new('foo')
62
- pre = q.size
63
- jid = Sidekiq::Client.push('queue' => 'foo', 'class' => 'MyWorker', 'args' => [1, 2])
64
- assert jid
65
- assert_equal 24, jid.size
66
- assert_equal pre + 1, q.size
67
- end
68
-
69
- class MyWorker
70
- include Sidekiq::Worker
71
- end
72
-
73
- class QueuedWorker
74
- include Sidekiq::Worker
75
- sidekiq_options :queue => :flimflam
76
- end
77
-
78
- it 'enqueues' do
79
- Sidekiq.redis {|c| c.flushdb }
80
- assert_equal Sidekiq.default_worker_options, MyWorker.get_sidekiq_options
81
- assert MyWorker.perform_async(1, 2)
82
- assert Sidekiq::Client.enqueue(MyWorker, 1, 2)
83
- assert Sidekiq::Client.enqueue_to(:custom_queue, MyWorker, 1, 2)
84
- assert_equal 1, Sidekiq::Queue.new('custom_queue').size
85
- assert Sidekiq::Client.enqueue_to_in(:custom_queue, 3.minutes, MyWorker, 1, 2)
86
- assert Sidekiq::Client.enqueue_to_in(:custom_queue, -3.minutes, MyWorker, 1, 2)
87
- assert_equal 2, Sidekiq::Queue.new('custom_queue').size
88
- assert Sidekiq::Client.enqueue_in(3.minutes, MyWorker, 1, 2)
89
- assert QueuedWorker.perform_async(1, 2)
90
- assert_equal 1, Sidekiq::Queue.new('flimflam').size
91
- end
92
- end
93
-
94
- describe 'bulk' do
95
- after do
96
- Sidekiq::Queue.new.clear
97
- end
98
- it 'can push a large set of jobs at once' do
99
- jids = Sidekiq::Client.push_bulk('class' => QueuedWorker, 'args' => (1..1_000).to_a.map { |x| Array(x) })
100
- assert_equal 1_000, jids.size
101
- end
102
- it 'can push a large set of jobs at once using a String class' do
103
- jids = Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..1_000).to_a.map { |x| Array(x) })
104
- assert_equal 1_000, jids.size
105
- end
106
- it 'returns the jids for the jobs' do
107
- Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => (1..2).to_a.map { |x| Array(x) }).each do |jid|
108
- assert_match(/[0-9a-f]{12}/, jid)
109
- end
110
- end
111
- end
112
-
113
- class BaseWorker
114
- include Sidekiq::Worker
115
- sidekiq_options 'retry' => 'base'
116
- end
117
- class AWorker < BaseWorker
118
- end
119
- class BWorker < BaseWorker
120
- sidekiq_options 'retry' => 'b'
121
- end
122
- class CWorker < BaseWorker
123
- sidekiq_options 'retry' => 2
124
- end
125
-
126
- describe 'client middleware' do
127
- class Stopper
128
- def call(worker_class, job, queue, r)
129
- raise ArgumentError unless r
130
- yield if job['args'].first.odd?
131
- end
132
- end
133
-
134
- it 'can stop some of the jobs from pushing' do
135
- client = Sidekiq::Client.new
136
- client.middleware do |chain|
137
- chain.add Stopper
138
- end
139
-
140
- assert_equal nil, client.push('class' => MyWorker, 'args' => [0])
141
- assert_match(/[0-9a-f]{12}/, client.push('class' => MyWorker, 'args' => [1]))
142
- client.push_bulk('class' => MyWorker, 'args' => [[0], [1]]).each do |jid|
143
- assert_match(/[0-9a-f]{12}/, jid)
144
- end
145
- end
146
- end
147
-
148
- describe 'inheritance' do
149
- it 'inherits sidekiq options' do
150
- assert_equal 'base', AWorker.get_sidekiq_options['retry']
151
- assert_equal 'b', BWorker.get_sidekiq_options['retry']
152
- end
153
- end
154
-
155
- describe 'sharding' do
156
- class DWorker < BaseWorker
157
- end
158
-
159
- it 'allows sidekiq_options to point to different Redi' do
160
- conn = MiniTest::Mock.new
161
- conn.expect(:multi, [0, 1])
162
- DWorker.sidekiq_options('pool' => ConnectionPool.new(size: 1) { conn })
163
- DWorker.perform_async(1,2,3)
164
- conn.verify
165
- end
166
-
167
- it 'allows #via to point to different Redi' do
168
- conn = MiniTest::Mock.new
169
- conn.expect(:multi, [0, 1])
170
- default = Sidekiq::Client.new.redis_pool
171
- sharded_pool = ConnectionPool.new(size: 1) { conn }
172
- Sidekiq::Client.via(sharded_pool) do
173
- CWorker.perform_async(1,2,3)
174
- assert_equal sharded_pool, Sidekiq::Client.new.redis_pool
175
- assert_raises RuntimeError do
176
- Sidekiq::Client.via(default) do
177
- # nothing
178
- end
179
- end
180
- end
181
- assert_equal default, Sidekiq::Client.new.redis_pool
182
- conn.verify
183
- end
184
-
185
- it 'allows Resque helpers to point to different Redi' do
186
- conn = MiniTest::Mock.new
187
- conn.expect(:multi, []) { |*args, &block| block.call }
188
- conn.expect(:zadd, 1, [String, Array])
189
- DWorker.sidekiq_options('pool' => ConnectionPool.new(size: 1) { conn })
190
- Sidekiq::Client.enqueue_in(10, DWorker, 3)
191
- conn.verify
192
- end
193
- end
194
- end