sidekiq 4.2.9 → 4.2.10

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/issue_template.md +6 -1
  3. data/.travis.yml +10 -5
  4. data/Changes.md +9 -0
  5. data/Ent-Changes.md +9 -0
  6. data/Pro-Changes.md +29 -0
  7. data/bin/sidekiqload +11 -11
  8. data/lib/sidekiq.rb +1 -1
  9. data/lib/sidekiq/api.rb +20 -12
  10. data/lib/sidekiq/middleware/server/logging.rb +8 -17
  11. data/lib/sidekiq/processor.rb +16 -7
  12. data/lib/sidekiq/testing.rb +6 -0
  13. data/lib/sidekiq/version.rb +1 -1
  14. data/lib/sidekiq/web/application.rb +2 -2
  15. data/lib/sidekiq/web/helpers.rb +2 -1
  16. data/sidekiq.gemspec +8 -2
  17. data/web/assets/javascripts/dashboard.js +1 -1
  18. data/web/locales/fa.yml +79 -0
  19. data/web/views/_job_info.erb +1 -1
  20. data/web/views/dashboard.erb +2 -2
  21. data/web/views/morgue.erb +2 -0
  22. data/web/views/queue.erb +2 -2
  23. data/web/views/queues.erb +2 -2
  24. data/web/views/retry.erb +1 -1
  25. metadata +74 -63
  26. data/test/config.yml +0 -9
  27. data/test/env_based_config.yml +0 -11
  28. data/test/fake_env.rb +0 -1
  29. data/test/fixtures/en.yml +0 -2
  30. data/test/helper.rb +0 -75
  31. data/test/test_actors.rb +0 -138
  32. data/test/test_api.rb +0 -528
  33. data/test/test_cli.rb +0 -418
  34. data/test/test_client.rb +0 -266
  35. data/test/test_exception_handler.rb +0 -56
  36. data/test/test_extensions.rb +0 -129
  37. data/test/test_fetch.rb +0 -50
  38. data/test/test_launcher.rb +0 -92
  39. data/test/test_logging.rb +0 -35
  40. data/test/test_manager.rb +0 -50
  41. data/test/test_middleware.rb +0 -158
  42. data/test/test_processor.rb +0 -249
  43. data/test/test_rails.rb +0 -22
  44. data/test/test_redis_connection.rb +0 -132
  45. data/test/test_retry.rb +0 -326
  46. data/test/test_retry_exhausted.rb +0 -149
  47. data/test/test_scheduled.rb +0 -115
  48. data/test/test_scheduling.rb +0 -58
  49. data/test/test_sidekiq.rb +0 -107
  50. data/test/test_testing.rb +0 -143
  51. data/test/test_testing_fake.rb +0 -359
  52. data/test/test_testing_inline.rb +0 -94
  53. data/test/test_util.rb +0 -13
  54. data/test/test_web.rb +0 -679
  55. data/test/test_web_helpers.rb +0 -54
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative 'helper'
3
-
4
- class TestUtil < Sidekiq::Test
5
-
6
- class Helpers
7
- include Sidekiq::Util
8
- end
9
-
10
- def test_nothing_atm
11
- assert true
12
- end
13
- end
@@ -1,679 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require_relative 'helper'
4
- require 'sidekiq/web'
5
- require 'rack/test'
6
-
7
- class TestWeb < Sidekiq::Test
8
- describe 'sidekiq web' do
9
- include Rack::Test::Methods
10
-
11
- def app
12
- Sidekiq::Web
13
- end
14
-
15
- def job_params(job, score)
16
- "#{score}-#{job['jid']}"
17
- end
18
-
19
- before do
20
- Sidekiq.redis {|c| c.flushdb }
21
- end
22
-
23
- class WebWorker
24
- include Sidekiq::Worker
25
-
26
- def perform(a, b)
27
- a + b
28
- end
29
- end
30
-
31
- it 'can configure via set() syntax' do
32
- app.set(:session_secret, "foo")
33
- assert_equal "foo", app.session_secret
34
- end
35
-
36
- it 'can show text with any locales' do
37
- rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'ru,en'}
38
- get '/', {}, rackenv
39
- assert_match(/Панель управления/, last_response.body)
40
- rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'es,en'}
41
- get '/', {}, rackenv
42
- assert_match(/Panel de Control/, last_response.body)
43
- rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'en-us'}
44
- get '/', {}, rackenv
45
- assert_match(/Dashboard/, last_response.body)
46
- rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'zh-cn'}
47
- get '/', {}, rackenv
48
- assert_match(/信息板/, last_response.body)
49
- rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'zh-tw'}
50
- get '/', {}, rackenv
51
- assert_match(/資訊主頁/, last_response.body)
52
- rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'nb'}
53
- get '/', {}, rackenv
54
- assert_match(/Oversikt/, last_response.body)
55
- end
56
-
57
- describe 'busy' do
58
-
59
- it 'can display workers' do
60
- Sidekiq.redis do |conn|
61
- conn.incr('busy')
62
- conn.sadd('processes', 'foo:1234')
63
- conn.hmset('foo:1234', 'info', Sidekiq.dump_json('hostname' => 'foo', 'started_at' => Time.now.to_f, "queues" => []), 'at', Time.now.to_f, 'busy', 4)
64
- identity = 'foo:1234:workers'
65
- hash = {:queue => 'critical', :payload => { 'class' => WebWorker.name, 'args' => [1,'abc'] }, :run_at => Time.now.to_i }
66
- conn.hmset(identity, 1001, Sidekiq.dump_json(hash))
67
- end
68
- assert_equal ['1001'], Sidekiq::Workers.new.map { |pid, tid, data| tid }
69
-
70
- get '/busy'
71
- assert_equal 200, last_response.status
72
- assert_match(/status-active/, last_response.body)
73
- assert_match(/critical/, last_response.body)
74
- assert_match(/WebWorker/, last_response.body)
75
- end
76
-
77
- it 'can quiet a process' do
78
- identity = 'identity'
79
- signals_key = "#{identity}-signals"
80
-
81
- assert_nil Sidekiq.redis { |c| c.lpop signals_key }
82
- post '/busy', 'quiet' => '1', 'identity' => identity
83
- assert_equal 302, last_response.status
84
- assert_equal 'USR1', Sidekiq.redis { |c| c.lpop signals_key }
85
- end
86
-
87
- it 'can stop a process' do
88
- identity = 'identity'
89
- signals_key = "#{identity}-signals"
90
-
91
- assert_nil Sidekiq.redis { |c| c.lpop signals_key }
92
- post '/busy', 'stop' => '1', 'identity' => identity
93
- assert_equal 302, last_response.status
94
- assert_equal 'TERM', Sidekiq.redis { |c| c.lpop signals_key }
95
- end
96
- end
97
-
98
- it 'can display queues' do
99
- assert Sidekiq::Client.push('queue' => :foo, 'class' => WebWorker, 'args' => [1, 3])
100
-
101
- get '/queues'
102
- assert_equal 200, last_response.status
103
- assert_match(/foo/, last_response.body)
104
- refute_match(/HardWorker/, last_response.body)
105
- end
106
-
107
- it 'handles queue view' do
108
- get '/queues/default'
109
- assert_equal 200, last_response.status
110
- end
111
-
112
- it 'can delete a queue' do
113
- Sidekiq.redis do |conn|
114
- conn.rpush('queue:foo', '{}')
115
- conn.sadd('queues', 'foo')
116
- end
117
-
118
- get '/queues/foo'
119
- assert_equal 200, last_response.status
120
-
121
- post '/queues/foo'
122
- assert_equal 302, last_response.status
123
-
124
- Sidekiq.redis do |conn|
125
- refute conn.smembers('queues').include?('foo')
126
- refute conn.exists('queue:foo')
127
- end
128
- end
129
-
130
- it 'can delete a job' do
131
- Sidekiq.redis do |conn|
132
- conn.rpush('queue:foo', "{}")
133
- conn.rpush('queue:foo', "{\"foo\":\"bar\"}")
134
- conn.rpush('queue:foo', "{\"foo2\":\"bar2\"}")
135
- end
136
-
137
- get '/queues/foo'
138
- assert_equal 200, last_response.status
139
-
140
- post '/queues/foo/delete', key_val: "{\"foo\":\"bar\"}"
141
- assert_equal 302, last_response.status
142
-
143
- Sidekiq.redis do |conn|
144
- refute conn.lrange('queue:foo', 0, -1).include?("{\"foo\":\"bar\"}")
145
- end
146
- end
147
-
148
- it 'can display retries' do
149
- get '/retries'
150
- assert_equal 200, last_response.status
151
- assert_match(/found/, last_response.body)
152
- refute_match(/HardWorker/, last_response.body)
153
-
154
- add_retry
155
-
156
- get '/retries'
157
- assert_equal 200, last_response.status
158
- refute_match(/found/, last_response.body)
159
- assert_match(/HardWorker/, last_response.body)
160
- end
161
-
162
- it 'can display a single retry' do
163
- params = add_retry
164
- get '/retries/0-shouldntexist'
165
- assert_equal 302, last_response.status
166
- get "/retries/#{job_params(*params)}"
167
- assert_equal 200, last_response.status
168
- assert_match(/HardWorker/, last_response.body)
169
- end
170
-
171
- it 'handles missing retry' do
172
- get "/retries/0-shouldntexist"
173
- assert_equal 302, last_response.status
174
- end
175
-
176
- it 'can delete a single retry' do
177
- params = add_retry
178
- post "/retries/#{job_params(*params)}", 'delete' => 'Delete'
179
- assert_equal 302, last_response.status
180
- assert_equal 'http://example.org/retries', last_response.header['Location']
181
-
182
- get "/retries"
183
- assert_equal 200, last_response.status
184
- refute_match(/#{params.first['args'][2]}/, last_response.body)
185
- end
186
-
187
- it 'can delete all retries' do
188
- 3.times { add_retry }
189
-
190
- post "/retries/all/delete", 'delete' => 'Delete'
191
- assert_equal 0, Sidekiq::RetrySet.new.size
192
- assert_equal 302, last_response.status
193
- assert_equal 'http://example.org/retries', last_response.header['Location']
194
- end
195
-
196
- it 'can retry a single retry now' do
197
- params = add_retry
198
- post "/retries/#{job_params(*params)}", 'retry' => 'Retry'
199
- assert_equal 302, last_response.status
200
- assert_equal 'http://example.org/retries', last_response.header['Location']
201
-
202
- get '/queues/default'
203
- assert_equal 200, last_response.status
204
- assert_match(/#{params.first['args'][2]}/, last_response.body)
205
- end
206
-
207
- it 'can kill a single retry now' do
208
- params = add_retry
209
- post "/retries/#{job_params(*params)}", 'kill' => 'Kill'
210
- assert_equal 302, last_response.status
211
- assert_equal 'http://example.org/retries', last_response.header['Location']
212
-
213
- get '/morgue'
214
- assert_equal 200, last_response.status
215
- assert_match(/#{params.first['args'][2]}/, last_response.body)
216
- end
217
-
218
- it 'can display scheduled' do
219
- get '/scheduled'
220
- assert_equal 200, last_response.status
221
- assert_match(/found/, last_response.body)
222
- refute_match(/HardWorker/, last_response.body)
223
-
224
- add_scheduled
225
-
226
- get '/scheduled'
227
- assert_equal 200, last_response.status
228
- refute_match(/found/, last_response.body)
229
- assert_match(/HardWorker/, last_response.body)
230
- end
231
-
232
- it 'can display a single scheduled job' do
233
- params = add_scheduled
234
- get '/scheduled/0-shouldntexist'
235
- assert_equal 302, last_response.status
236
- get "/scheduled/#{job_params(*params)}"
237
- assert_equal 200, last_response.status
238
- assert_match(/HardWorker/, last_response.body)
239
- end
240
-
241
- it 'handles missing scheduled job' do
242
- get "/scheduled/0-shouldntexist"
243
- assert_equal 302, last_response.status
244
- end
245
-
246
- it 'can add to queue a single scheduled job' do
247
- params = add_scheduled
248
- post "/scheduled/#{job_params(*params)}", 'add_to_queue' => true
249
- assert_equal 302, last_response.status
250
- assert_equal 'http://example.org/scheduled', last_response.header['Location']
251
-
252
- get '/queues/default'
253
- assert_equal 200, last_response.status
254
- assert_match(/#{params.first['args'][2]}/, last_response.body)
255
- end
256
-
257
- it 'can delete a single scheduled job' do
258
- params = add_scheduled
259
- post "/scheduled/#{job_params(*params)}", 'delete' => 'Delete'
260
- assert_equal 302, last_response.status
261
- assert_equal 'http://example.org/scheduled', last_response.header['Location']
262
-
263
- get "/scheduled"
264
- assert_equal 200, last_response.status
265
- refute_match(/#{params.first['args'][2]}/, last_response.body)
266
- end
267
-
268
- it 'can delete scheduled' do
269
- params = add_scheduled
270
- Sidekiq.redis do |conn|
271
- assert_equal 1, conn.zcard('schedule')
272
- post '/scheduled', 'key' => [job_params(*params)], 'delete' => 'Delete'
273
- assert_equal 302, last_response.status
274
- assert_equal 'http://example.org/scheduled', last_response.header['Location']
275
- assert_equal 0, conn.zcard('schedule')
276
- end
277
- end
278
-
279
- it "can move scheduled to default queue" do
280
- q = Sidekiq::Queue.new
281
- params = add_scheduled
282
- Sidekiq.redis do |conn|
283
- assert_equal 1, conn.zcard('schedule')
284
- assert_equal 0, q.size
285
- post '/scheduled', 'key' => [job_params(*params)], 'add_to_queue' => 'AddToQueue'
286
- assert_equal 302, last_response.status
287
- assert_equal 'http://example.org/scheduled', last_response.header['Location']
288
- assert_equal 0, conn.zcard('schedule')
289
- assert_equal 1, q.size
290
- get '/queues/default'
291
- assert_equal 200, last_response.status
292
- assert_match(/#{params[0]['args'][2]}/, last_response.body)
293
- end
294
- end
295
-
296
- it 'can retry all retries' do
297
- msg = add_retry.first
298
- add_retry
299
-
300
- post "/retries/all/retry", 'retry' => 'Retry'
301
- assert_equal 302, last_response.status
302
- assert_equal 'http://example.org/retries', last_response.header['Location']
303
- assert_equal 2, Sidekiq::Queue.new("default").size
304
-
305
- get '/queues/default'
306
- assert_equal 200, last_response.status
307
- assert_match(/#{msg['args'][2]}/, last_response.body)
308
- end
309
-
310
- it 'calls updatePage() once when polling' do
311
- get '/busy?poll=true'
312
- assert_equal 200, last_response.status
313
- assert_equal 1, last_response.body.scan('data-poll-path="/busy').count
314
- end
315
-
316
- it 'escape job args and error messages' do
317
- # on /retries page
318
- params = add_xss_retry
319
- get '/retries'
320
- assert_equal 200, last_response.status
321
- assert_match(/FailWorker/, last_response.body)
322
-
323
- assert last_response.body.include?( "fail message: &lt;a&gt;hello&lt;&#x2F;a&gt;" )
324
- assert !last_response.body.include?( "fail message: <a>hello</a>" )
325
-
326
- assert last_response.body.include?( "args\">&quot;&lt;a&gt;hello&lt;&#x2F;a&gt;&quot;<" )
327
- assert !last_response.body.include?( "args\"><a>hello</a><" )
328
-
329
- # on /workers page
330
- Sidekiq.redis do |conn|
331
- pro = 'foo:1234'
332
- conn.sadd('processes', pro)
333
- conn.hmset(pro, 'info', Sidekiq.dump_json('started_at' => Time.now.to_f, 'labels' => ['frumduz'], 'queues' =>[]), 'busy', 1, 'beat', Time.now.to_f)
334
- identity = "#{pro}:workers"
335
- hash = {:queue => 'critical', :payload => { 'class' => "FailWorker", 'args' => ["<a>hello</a>"] }, :run_at => Time.now.to_i }
336
- conn.hmset(identity, 100001, Sidekiq.dump_json(hash))
337
- conn.incr('busy')
338
- end
339
-
340
- get '/busy'
341
- assert_equal 200, last_response.status
342
- assert_match(/FailWorker/, last_response.body)
343
- assert_match(/frumduz/, last_response.body)
344
- assert last_response.body.include?( "&lt;a&gt;hello&lt;&#x2F;a&gt;" )
345
- assert !last_response.body.include?( "<a>hello</a>" )
346
-
347
- # on /queues page
348
- params = add_xss_retry # sorry, don't know how to easily make this show up on queues page otherwise.
349
- post "/retries/#{job_params(*params)}", 'retry' => 'Retry'
350
- assert_equal 302, last_response.status
351
-
352
- get '/queues/foo'
353
- assert_equal 200, last_response.status
354
- assert last_response.body.include?( "&lt;a&gt;hello&lt;&#x2F;a&gt;" )
355
- assert !last_response.body.include?( "<a>hello</a>" )
356
- end
357
-
358
- it 'can show user defined tab' do
359
- begin
360
- Sidekiq::Web.tabs['Custom Tab'] = '/custom'
361
-
362
- get '/'
363
- assert_match 'Custom Tab', last_response.body
364
-
365
- ensure
366
- Sidekiq::Web.tabs.delete 'Custom Tab'
367
- end
368
- end
369
-
370
- it 'can display home' do
371
- get '/'
372
- assert_equal 200, last_response.status
373
- end
374
-
375
- describe 'custom locales' do
376
- before do
377
- Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
378
- Sidekiq::Web.tabs['Custom Tab'] = '/custom'
379
- Sidekiq::WebApplication.get('/custom') do
380
- clear_caches # ugly hack since I can't figure out how to access WebHelpers outside of this context
381
- t('translated_text')
382
- end
383
- end
384
-
385
- after do
386
- Sidekiq::Web.tabs.delete 'Custom Tab'
387
- Sidekiq::Web.settings.locales.pop
388
- end
389
-
390
- it 'can show user defined tab with custom locales' do
391
- get '/custom'
392
-
393
- assert_match(/Changed text/, last_response.body)
394
- end
395
- end
396
-
397
- describe 'dashboard/stats' do
398
- it 'redirects to stats' do
399
- get '/dashboard/stats'
400
- assert_equal 302, last_response.status
401
- assert_equal 'http://example.org/stats', last_response.header['Location']
402
- end
403
- end
404
-
405
- describe 'stats' do
406
- include Sidekiq::Util
407
-
408
- before do
409
- Sidekiq.redis do |conn|
410
- conn.set("stat:processed", 5)
411
- conn.set("stat:failed", 2)
412
- conn.sadd("queues", "default")
413
- end
414
- 2.times { add_retry }
415
- 3.times { add_scheduled }
416
- 4.times { add_worker }
417
- end
418
-
419
- it 'works' do
420
- get '/stats'
421
- @response = Sidekiq.load_json(last_response.body)
422
- assert_equal 200, last_response.status
423
- assert_includes @response.keys, "sidekiq"
424
- assert_equal 5, @response["sidekiq"]["processed"]
425
- assert_equal 2, @response["sidekiq"]["failed"]
426
- assert_equal 4, @response["sidekiq"]["busy"]
427
- assert_equal 1, @response["sidekiq"]["processes"]
428
- assert_equal 2, @response["sidekiq"]["retries"]
429
- assert_equal 3, @response["sidekiq"]["scheduled"]
430
- assert_equal 0, @response["sidekiq"]["default_latency"]
431
- assert_includes @response.keys, "redis"
432
- assert_includes @response["redis"].keys, "redis_version"
433
- assert_includes @response["redis"].keys, "uptime_in_days"
434
- assert_includes @response["redis"].keys, "connected_clients"
435
- assert_includes @response["redis"].keys, "used_memory_human"
436
- assert_includes @response["redis"].keys, "used_memory_peak_human"
437
- end
438
- end
439
-
440
- describe 'stats/queues' do
441
- include Sidekiq::Util
442
-
443
- before do
444
- Sidekiq.redis do |conn|
445
- conn.set("stat:processed", 5)
446
- conn.set("stat:failed", 2)
447
- conn.sadd("queues", "default")
448
- conn.sadd("queues", "queue2")
449
- end
450
- 2.times { add_retry }
451
- 3.times { add_scheduled }
452
- 4.times { add_worker }
453
-
454
- get '/stats/queues'
455
- @response = Sidekiq.load_json(last_response.body)
456
- end
457
-
458
- it 'reports the queue depth' do
459
- assert_equal 0, @response["default"]
460
- assert_equal 0, @response["queue2"]
461
- end
462
- end
463
-
464
- describe 'dead jobs' do
465
- it 'shows empty index' do
466
- get 'morgue'
467
- assert_equal 200, last_response.status
468
- end
469
-
470
- it 'shows index with jobs' do
471
- (_, score) = add_dead
472
- get 'morgue'
473
- assert_equal 200, last_response.status
474
- assert_match(/#{score}/, last_response.body)
475
- end
476
-
477
- it 'can delete all dead' do
478
- 3.times { add_dead }
479
-
480
- assert_equal 3, Sidekiq::DeadSet.new.size
481
- post "/morgue/all/delete", 'delete' => 'Delete'
482
- assert_equal 0, Sidekiq::DeadSet.new.size
483
- assert_equal 302, last_response.status
484
- assert_equal 'http://example.org/morgue', last_response.header['Location']
485
- end
486
-
487
- it 'can retry a dead job' do
488
- params = add_dead
489
- post "/morgue/#{job_params(*params)}", 'retry' => 'Retry'
490
- assert_equal 302, last_response.status
491
- assert_equal 'http://example.org/morgue', last_response.header['Location']
492
-
493
- get '/queues/foo'
494
- assert_equal 200, last_response.status
495
- assert_match(/#{params.first['args'][2]}/, last_response.body)
496
- end
497
- end
498
-
499
- def add_scheduled
500
- score = Time.now.to_f
501
- msg = { 'class' => 'HardWorker',
502
- 'args' => ['bob', 1, Time.now.to_f],
503
- 'jid' => SecureRandom.hex(12) }
504
- Sidekiq.redis do |conn|
505
- conn.zadd('schedule', score, Sidekiq.dump_json(msg))
506
- end
507
- [msg, score]
508
- end
509
-
510
- def add_retry
511
- msg = { 'class' => 'HardWorker',
512
- 'args' => ['bob', 1, Time.now.to_f],
513
- 'queue' => 'default',
514
- 'error_message' => 'Some fake message',
515
- 'error_class' => 'RuntimeError',
516
- 'retry_count' => 0,
517
- 'failed_at' => Time.now.to_f,
518
- 'jid' => SecureRandom.hex(12) }
519
- score = Time.now.to_f
520
- Sidekiq.redis do |conn|
521
- conn.zadd('retry', score, Sidekiq.dump_json(msg))
522
- end
523
-
524
- [msg, score]
525
- end
526
-
527
- def add_dead
528
- msg = { 'class' => 'HardWorker',
529
- 'args' => ['bob', 1, Time.now.to_f],
530
- 'queue' => 'foo',
531
- 'error_message' => 'Some fake message',
532
- 'error_class' => 'RuntimeError',
533
- 'retry_count' => 0,
534
- 'failed_at' => Time.now.utc,
535
- 'jid' => SecureRandom.hex(12) }
536
- score = Time.now.to_f
537
- Sidekiq.redis do |conn|
538
- conn.zadd('dead', score, Sidekiq.dump_json(msg))
539
- end
540
- [msg, score]
541
- end
542
-
543
- def add_xss_retry
544
- msg = { 'class' => 'FailWorker',
545
- 'args' => ['<a>hello</a>'],
546
- 'queue' => 'foo',
547
- 'error_message' => 'fail message: <a>hello</a>',
548
- 'error_class' => 'RuntimeError',
549
- 'retry_count' => 0,
550
- 'failed_at' => Time.now.to_f,
551
- 'jid' => SecureRandom.hex(12) }
552
- score = Time.now.to_f
553
- Sidekiq.redis do |conn|
554
- conn.zadd('retry', score, Sidekiq.dump_json(msg))
555
- end
556
-
557
- [msg, score]
558
- end
559
-
560
- def add_worker
561
- key = "#{hostname}:#{$$}"
562
- msg = "{\"queue\":\"default\",\"payload\":{\"retry\":true,\"queue\":\"default\",\"timeout\":20,\"backtrace\":5,\"class\":\"HardWorker\",\"args\":[\"bob\",10,5],\"jid\":\"2b5ad2b016f5e063a1c62872\"},\"run_at\":1361208995}"
563
- Sidekiq.redis do |conn|
564
- conn.multi do
565
- conn.sadd("processes", key)
566
- conn.hmset(key, 'info', Sidekiq.dump_json('hostname' => 'foo', 'started_at' => Time.now.to_f, "queues" => []), 'at', Time.now.to_f, 'busy', 4)
567
- conn.hmset("#{key}:workers", Time.now.to_f, msg)
568
- end
569
- end
570
- end
571
- end
572
-
573
- describe 'sidekiq web with basic auth' do
574
- include Rack::Test::Methods
575
-
576
- def app
577
- app = Sidekiq::Web.new
578
- app.use(Rack::Auth::Basic) { |user, pass| user == "a" && pass == "b" }
579
-
580
- app
581
- end
582
-
583
- it 'requires basic authentication' do
584
- get '/'
585
-
586
- assert_equal 401, last_response.status
587
- refute_nil last_response.header["WWW-Authenticate"]
588
- end
589
-
590
- it 'authenticates successfuly' do
591
- basic_authorize 'a', 'b'
592
-
593
- get '/'
594
-
595
- assert_equal 200, last_response.status
596
- end
597
- end
598
-
599
- describe 'sidekiq web with custom session' do
600
- include Rack::Test::Methods
601
-
602
- def app
603
- app = Sidekiq::Web.new
604
-
605
- app.use Rack::Session::Cookie, secret: 'v3rys3cr31', host: 'nicehost.org'
606
-
607
- app
608
- end
609
-
610
- it 'requires basic authentication' do
611
- get '/'
612
-
613
- session_options = last_request.env['rack.session'].options
614
-
615
- assert_equal 'v3rys3cr31', session_options[:secret]
616
- assert_equal 'nicehost.org', session_options[:host]
617
- end
618
- end
619
-
620
- describe 'sidekiq web sessions options' do
621
- include Rack::Test::Methods
622
-
623
- describe 'using #disable' do
624
- def app
625
- app = Sidekiq::Web.new
626
- app.disable(:sessions)
627
- app
628
- end
629
-
630
- it "doesn't create sessions" do
631
- get '/'
632
- assert_nil last_request.env['rack.session']
633
- end
634
- end
635
-
636
- describe 'using #set with false argument' do
637
- def app
638
- app = Sidekiq::Web.new
639
- app.set(:sessions, false)
640
- app
641
- end
642
-
643
- it "doesn't create sessions" do
644
- get '/'
645
- assert_nil last_request.env['rack.session']
646
- end
647
- end
648
-
649
- describe 'using #set with an hash' do
650
- def app
651
- app = Sidekiq::Web.new
652
- app.set(:sessions, { domain: :all })
653
- app
654
- end
655
-
656
- it "creates sessions" do
657
- get '/'
658
- refute_nil last_request.env['rack.session']
659
- refute_empty last_request.env['rack.session'].options
660
- assert_equal :all, last_request.env['rack.session'].options[:domain]
661
- end
662
- end
663
-
664
- describe 'using #enable' do
665
- def app
666
- app = Sidekiq::Web.new
667
- app.enable(:sessions)
668
- app
669
- end
670
-
671
- it "creates sessions" do
672
- get '/'
673
- refute_nil last_request.env['rack.session']
674
- refute_empty last_request.env['rack.session'].options
675
- refute_nil last_request.env['rack.session'].options[:secret]
676
- end
677
- end
678
- end
679
- end