sidekiq 5.0.0.beta1 → 5.0.0.beta2

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +6 -0
  3. data/Pro-Changes.md +3 -2
  4. data/bin/sidekiqload +11 -11
  5. data/lib/sidekiq/api.rb +15 -8
  6. data/lib/sidekiq/job_retry.rb +15 -12
  7. data/lib/sidekiq/processor.rb +3 -2
  8. data/lib/sidekiq/version.rb +1 -1
  9. data/lib/sidekiq/web/application.rb +1 -1
  10. data/lib/sidekiq/web/helpers.rb +2 -1
  11. data/sidekiq.gemspec +2 -2
  12. data/web/views/retry.erb +1 -1
  13. metadata +3 -67
  14. data/test/config.yml +0 -9
  15. data/test/env_based_config.yml +0 -11
  16. data/test/fake_env.rb +0 -1
  17. data/test/fixtures/en.yml +0 -2
  18. data/test/helper.rb +0 -98
  19. data/test/test_actors.rb +0 -138
  20. data/test/test_api.rb +0 -529
  21. data/test/test_cli.rb +0 -418
  22. data/test/test_client.rb +0 -266
  23. data/test/test_exception_handler.rb +0 -56
  24. data/test/test_extensions.rb +0 -115
  25. data/test/test_fetch.rb +0 -50
  26. data/test/test_launcher.rb +0 -92
  27. data/test/test_logging.rb +0 -35
  28. data/test/test_manager.rb +0 -50
  29. data/test/test_middleware.rb +0 -158
  30. data/test/test_processor.rb +0 -266
  31. data/test/test_rails.rb +0 -22
  32. data/test/test_redis_connection.rb +0 -132
  33. data/test/test_retry.rb +0 -335
  34. data/test/test_retry_exhausted.rb +0 -149
  35. data/test/test_scheduled.rb +0 -115
  36. data/test/test_scheduling.rb +0 -58
  37. data/test/test_sidekiq.rb +0 -107
  38. data/test/test_testing.rb +0 -135
  39. data/test/test_testing_fake.rb +0 -352
  40. data/test/test_testing_inline.rb +0 -93
  41. data/test/test_util.rb +0 -13
  42. data/test/test_web.rb +0 -638
  43. data/test/test_web_auth.rb +0 -54
  44. data/test/test_web_helpers.rb +0 -54
  45. data/test/test_web_sessions.rb +0 -67
@@ -1,149 +0,0 @@
1
- # encoding: utf-8
2
- require_relative 'helper'
3
- require 'sidekiq/job_retry'
4
-
5
- class TestRetryExhausted < Sidekiq::Test
6
- describe 'sidekiq_retries_exhausted' do
7
- class NewWorker
8
- include Sidekiq::Worker
9
-
10
- class_attribute :exhausted_called, :exhausted_job, :exhausted_exception
11
-
12
- sidekiq_retries_exhausted do |job, e|
13
- self.exhausted_called = true
14
- self.exhausted_job = job
15
- self.exhausted_exception = e
16
- end
17
- end
18
-
19
- class OldWorker
20
- include Sidekiq::Worker
21
-
22
- class_attribute :exhausted_called, :exhausted_job, :exhausted_exception
23
-
24
- sidekiq_retries_exhausted do |job|
25
- self.exhausted_called = true
26
- self.exhausted_job = job
27
- end
28
- end
29
-
30
- def cleanup
31
- [NewWorker, OldWorker].each do |worker_class|
32
- worker_class.exhausted_called = nil
33
- worker_class.exhausted_job = nil
34
- worker_class.exhausted_exception = nil
35
- end
36
- end
37
-
38
- before do
39
- cleanup
40
- end
41
-
42
- after do
43
- cleanup
44
- end
45
-
46
- def new_worker
47
- @new_worker ||= NewWorker.new
48
- end
49
-
50
- def old_worker
51
- @old_worker ||= OldWorker.new
52
- end
53
-
54
- def handler(options={})
55
- @handler ||= Sidekiq::JobRetry.new(options)
56
- end
57
-
58
- def job(options={})
59
- @job ||= {'class' => 'Bob', 'args' => [1, 2, 'foo']}.merge(options)
60
- end
61
-
62
- it 'does not run exhausted block when job successful on first run' do
63
- handler.local(new_worker, job('retry' => 2), 'default') do
64
- # successful
65
- end
66
-
67
- refute NewWorker.exhausted_called?
68
- end
69
-
70
- it 'does not run exhausted block when job successful on last retry' do
71
- handler.local(new_worker, job('retry_count' => 0, 'retry' => 1), 'default') do
72
- # successful
73
- end
74
-
75
- refute NewWorker.exhausted_called?
76
- end
77
-
78
- it 'does not run exhausted block when retries not exhausted yet' do
79
- assert_raises RuntimeError do
80
- handler.local(new_worker, job('retry' => 1), 'default') do
81
- raise 'kerblammo!'
82
- end
83
- end
84
-
85
- refute NewWorker.exhausted_called?
86
- end
87
-
88
- it 'runs exhausted block when retries exhausted' do
89
- assert_raises RuntimeError do
90
- handler.local(new_worker, job('retry_count' => 0, 'retry' => 1), 'default') do
91
- raise 'kerblammo!'
92
- end
93
- end
94
-
95
- assert NewWorker.exhausted_called?
96
- end
97
-
98
-
99
- it 'passes job and exception to retries exhausted block' do
100
- raised_error = assert_raises RuntimeError do
101
- handler.local(new_worker, job('retry_count' => 0, 'retry' => 1), 'default') do
102
- raise 'kerblammo!'
103
- end
104
- end
105
-
106
- assert new_worker.exhausted_called?
107
- assert_equal raised_error.message, new_worker.exhausted_job['error_message']
108
- assert_equal raised_error, new_worker.exhausted_exception
109
- end
110
-
111
- it 'passes job to retries exhausted block' do
112
- raised_error = assert_raises RuntimeError do
113
- handler.local(old_worker, job('retry_count' => 0, 'retry' => 1), 'default') do
114
- raise 'kerblammo!'
115
- end
116
- end
117
-
118
- assert old_worker.exhausted_called?
119
- assert_equal raised_error.message, old_worker.exhausted_job['error_message']
120
- assert_nil new_worker.exhausted_exception
121
- end
122
-
123
- it 'allows a global default handler' do
124
- begin
125
- class Foobar
126
- include Sidekiq::Worker
127
- end
128
-
129
- exhausted_job = nil
130
- exhausted_exception = nil
131
- Sidekiq.default_retries_exhausted = lambda do |job, ex|
132
- exhausted_job = job
133
- exhausted_exception = ex
134
- end
135
- f = Foobar.new
136
- raised_error = assert_raises RuntimeError do
137
- handler.local(f, job('retry_count' => 0, 'retry' => 1), 'default') do
138
- raise 'kerblammo!'
139
- end
140
- end
141
-
142
- assert exhausted_job
143
- assert_equal raised_error, exhausted_exception
144
- ensure
145
- Sidekiq.default_retries_exhausted = nil
146
- end
147
- end
148
- end
149
- end
@@ -1,115 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative 'helper'
3
- require 'sidekiq/scheduled'
4
-
5
- class TestScheduled < Sidekiq::Test
6
- class ScheduledWorker
7
- include Sidekiq::Worker
8
- def perform(x)
9
- end
10
- end
11
-
12
- describe 'poller' do
13
- before do
14
- Sidekiq.redis{|c| c.flushdb}
15
- @error_1 = { 'class' => ScheduledWorker.name, 'args' => [0], 'queue' => 'queue_1' }
16
- @error_2 = { 'class' => ScheduledWorker.name, 'args' => [1], 'queue' => 'queue_2' }
17
- @error_3 = { 'class' => ScheduledWorker.name, 'args' => [2], 'queue' => 'queue_3' }
18
- @future_1 = { 'class' => ScheduledWorker.name, 'args' => [3], 'queue' => 'queue_4' }
19
- @future_2 = { 'class' => ScheduledWorker.name, 'args' => [4], 'queue' => 'queue_5' }
20
- @future_3 = { 'class' => ScheduledWorker.name, 'args' => [5], 'queue' => 'queue_6' }
21
-
22
- @retry = Sidekiq::RetrySet.new
23
- @scheduled = Sidekiq::ScheduledSet.new
24
- @poller = Sidekiq::Scheduled::Poller.new
25
- end
26
-
27
- class Stopper
28
- def call(worker_class, job, queue, r)
29
- yield if job['args'].first.odd?
30
- end
31
- end
32
-
33
- it 'executes client middleware' do
34
- Sidekiq.client_middleware.add Stopper
35
- begin
36
- @retry.schedule (Time.now - 60).to_f, @error_1
37
- @retry.schedule (Time.now - 60).to_f, @error_2
38
- @scheduled.schedule (Time.now - 60).to_f, @future_2
39
- @scheduled.schedule (Time.now - 60).to_f, @future_3
40
-
41
- @poller.enqueue
42
-
43
- assert_equal 0, Sidekiq::Queue.new("queue_1").size
44
- assert_equal 1, Sidekiq::Queue.new("queue_2").size
45
- assert_equal 0, Sidekiq::Queue.new("queue_5").size
46
- assert_equal 1, Sidekiq::Queue.new("queue_6").size
47
- ensure
48
- Sidekiq.client_middleware.remove Stopper
49
- end
50
- end
51
-
52
- it 'should empty the retry and scheduled queues up to the current time' do
53
- created_time = Time.new(2013, 2, 3)
54
- enqueued_time = Time.new(2013, 2, 4)
55
-
56
- Time.stub(:now, created_time) do
57
- @retry.schedule (enqueued_time - 60).to_f, @error_1.merge!('created_at' => created_time.to_f)
58
- @retry.schedule (enqueued_time - 50).to_f, @error_2.merge!('created_at' => created_time.to_f)
59
- @retry.schedule (enqueued_time + 60).to_f, @error_3.merge!('created_at' => created_time.to_f)
60
- @scheduled.schedule (enqueued_time - 60).to_f, @future_1.merge!('created_at' => created_time.to_f)
61
- @scheduled.schedule (enqueued_time - 50).to_f, @future_2.merge!('created_at' => created_time.to_f)
62
- @scheduled.schedule (enqueued_time + 60).to_f, @future_3.merge!('created_at' => created_time.to_f)
63
- end
64
-
65
- Time.stub(:now, enqueued_time) do
66
- @poller.enqueue
67
-
68
- Sidekiq.redis do |conn|
69
- %w(queue:queue_1 queue:queue_2 queue:queue_4 queue:queue_5).each do |queue_name|
70
- assert_equal 1, conn.llen(queue_name)
71
- job = Sidekiq.load_json(conn.lrange(queue_name, 0, -1)[0])
72
- assert_equal enqueued_time.to_f, job['enqueued_at']
73
- assert_equal created_time.to_f, job['created_at']
74
- end
75
- end
76
-
77
- assert_equal 1, @retry.size
78
- assert_equal 1, @scheduled.size
79
- end
80
- end
81
-
82
- def with_sidekiq_option(name, value)
83
- _original, Sidekiq.options[name] = Sidekiq.options[name], value
84
- begin
85
- yield
86
- ensure
87
- Sidekiq.options[name] = _original
88
- end
89
- end
90
-
91
- it 'generates random intervals that target a configured average' do
92
- with_sidekiq_option(:poll_interval_average, 10) do
93
- i = 500
94
- intervals = Array.new(i){ @poller.send(:random_poll_interval) }
95
-
96
- assert intervals.all?{|x| x >= 5}
97
- assert intervals.all?{|x| x <= 15}
98
- assert_in_delta 10, intervals.reduce(&:+).to_f / i, 0.5
99
- end
100
- end
101
-
102
- it 'calculates an average poll interval based on the number of known Sidekiq processes' do
103
- with_sidekiq_option(:average_scheduled_poll_interval, 10) do
104
- 3.times do |i|
105
- Sidekiq.redis do |conn|
106
- conn.sadd("processes", "process-#{i}")
107
- conn.hset("process-#{i}", "info", nil)
108
- end
109
- end
110
-
111
- assert_equal 30, @poller.send(:scaled_poll_interval)
112
- end
113
- end
114
- end
115
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative 'helper'
3
- require 'sidekiq/scheduled'
4
-
5
- class TestScheduling < Sidekiq::Test
6
- describe 'middleware' do
7
- class ScheduledWorker
8
- include Sidekiq::Worker
9
- sidekiq_options :queue => :custom_queue
10
- def perform(x)
11
- end
12
- end
13
-
14
- # Assume we can pass any class as time to perform_in
15
- class TimeDuck
16
- def to_f; 42.0 end
17
- end
18
-
19
- it 'schedules jobs' do
20
- ss = Sidekiq::ScheduledSet.new
21
- ss.clear
22
-
23
- assert_equal 0, ss.size
24
-
25
- assert ScheduledWorker.perform_in(600, 'mike')
26
- assert_equal 1, ss.size
27
-
28
- assert ScheduledWorker.perform_in(1.month, 'mike')
29
- assert_equal 2, ss.size
30
-
31
- assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
32
- assert_equal 3, ss.size
33
-
34
- q = Sidekiq::Queue.new("custom_queue")
35
- qs = q.size
36
- assert ScheduledWorker.perform_in(-300, 'mike')
37
- assert_equal 3, ss.size
38
- assert_equal qs+1, q.size
39
-
40
- assert Sidekiq::Client.push_bulk('class' => ScheduledWorker, 'args' => [['mike'], ['mike']], 'at' => 600)
41
- assert_equal 5, ss.size
42
-
43
- assert ScheduledWorker.perform_in(TimeDuck.new, 'samwise')
44
- assert_equal 6, ss.size
45
- end
46
-
47
- it 'removes the enqueued_at field when scheduling' do
48
- ss = Sidekiq::ScheduledSet.new
49
- ss.clear
50
-
51
- assert ScheduledWorker.perform_in(1.month, 'mike')
52
- job = ss.first
53
- assert job['created_at']
54
- refute job['enqueued_at']
55
- end
56
- end
57
-
58
- end
@@ -1,107 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
- require_relative 'helper'
4
-
5
- class TestSidekiq < Sidekiq::Test
6
- describe 'json processing' do
7
- it 'handles json' do
8
- assert_equal({"foo" => "bar"}, Sidekiq.load_json("{\"foo\":\"bar\"}"))
9
- assert_equal "{\"foo\":\"bar\"}", Sidekiq.dump_json({ "foo" => "bar" })
10
- end
11
- end
12
-
13
- describe "redis connection" do
14
- it "returns error without creating a connection if block is not given" do
15
- assert_raises(ArgumentError) do
16
- Sidekiq.redis
17
- end
18
- end
19
- end
20
-
21
- describe "❨╯°□°❩╯︵┻━┻" do
22
- before { $stdout = StringIO.new }
23
- after { $stdout = STDOUT }
24
-
25
- it "allows angry developers to express their emotional constitution and remedies it" do
26
- Sidekiq.❨╯°□°❩╯︵┻━┻
27
- assert_equal "Calm down, yo.\n", $stdout.string
28
- end
29
- end
30
-
31
- describe 'lifecycle events' do
32
- it 'handles invalid input' do
33
- Sidekiq.options[:lifecycle_events][:startup].clear
34
-
35
- e = assert_raises ArgumentError do
36
- Sidekiq.on(:startp)
37
- end
38
- assert_match(/Invalid event name/, e.message)
39
- e = assert_raises ArgumentError do
40
- Sidekiq.on('startup')
41
- end
42
- assert_match(/Symbols only/, e.message)
43
- Sidekiq.on(:startup) do
44
- 1 + 1
45
- end
46
-
47
- assert_equal 2, Sidekiq.options[:lifecycle_events][:startup].first.call
48
- end
49
- end
50
-
51
- describe 'default_worker_options' do
52
- it 'stringifies keys' do
53
- @old_options = Sidekiq.default_worker_options
54
- begin
55
- Sidekiq.default_worker_options = { queue: 'cat'}
56
- assert_equal 'cat', Sidekiq.default_worker_options['queue']
57
- ensure
58
- Sidekiq.default_worker_options = @old_options
59
- end
60
- end
61
- end
62
-
63
- describe 'error handling' do
64
- it 'deals with user-specified error handlers which raise errors' do
65
- output = capture_logging do
66
- begin
67
- Sidekiq.error_handlers << proc {|x, hash|
68
- raise 'boom'
69
- }
70
- cli = Sidekiq::CLI.new
71
- cli.handle_exception(RuntimeError.new("hello"))
72
- ensure
73
- Sidekiq.error_handlers.pop
74
- end
75
- end
76
- assert_includes output, "boom"
77
- assert_includes output, "ERROR"
78
- end
79
- end
80
-
81
- describe 'redis connection' do
82
- it 'does not continually retry' do
83
- assert_raises Redis::CommandError do
84
- Sidekiq.redis do |c|
85
- raise Redis::CommandError, "READONLY You can't write against a read only slave."
86
- end
87
- end
88
- end
89
-
90
- it 'reconnects if connection is flagged as readonly' do
91
- counts = []
92
- Sidekiq.redis do |c|
93
- counts << c.info['total_connections_received'].to_i
94
- raise Redis::CommandError, "READONLY You can't write against a read only slave." if counts.size == 1
95
- end
96
- assert_equal 2, counts.size
97
- assert_equal counts[0] + 1, counts[1]
98
- end
99
- end
100
-
101
- describe 'redis info' do
102
- it 'calls the INFO command which returns at least redis_version' do
103
- output = Sidekiq.redis_info
104
- assert_includes output.keys, "redis_version"
105
- end
106
- end
107
- end
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
- require_relative 'helper'
3
-
4
- class TestTesting < Sidekiq::Test
5
- describe 'sidekiq testing' do
6
- describe 'require/load sidekiq/testing.rb' do
7
- before do
8
- require 'sidekiq/testing'
9
- end
10
-
11
- after do
12
- Sidekiq::Testing.disable!
13
- end
14
-
15
- it 'enables fake testing' do
16
- Sidekiq::Testing.fake!
17
- assert Sidekiq::Testing.enabled?
18
- assert Sidekiq::Testing.fake?
19
- refute Sidekiq::Testing.inline?
20
- end
21
-
22
- it 'enables fake testing in a block' do
23
- Sidekiq::Testing.disable!
24
- assert Sidekiq::Testing.disabled?
25
- refute Sidekiq::Testing.fake?
26
-
27
- Sidekiq::Testing.fake! do
28
- assert Sidekiq::Testing.enabled?
29
- assert Sidekiq::Testing.fake?
30
- refute Sidekiq::Testing.inline?
31
- end
32
-
33
- refute Sidekiq::Testing.enabled?
34
- refute Sidekiq::Testing.fake?
35
- end
36
-
37
- it 'disables testing in a block' do
38
- Sidekiq::Testing.fake!
39
- assert Sidekiq::Testing.fake?
40
-
41
- Sidekiq::Testing.disable! do
42
- refute Sidekiq::Testing.fake?
43
- assert Sidekiq::Testing.disabled?
44
- end
45
-
46
- assert Sidekiq::Testing.fake?
47
- assert Sidekiq::Testing.enabled?
48
- end
49
- end
50
-
51
- describe 'require/load sidekiq/testing/inline.rb' do
52
- before do
53
- require 'sidekiq/testing/inline'
54
- end
55
-
56
- after do
57
- Sidekiq::Testing.disable!
58
- end
59
-
60
- it 'enables inline testing' do
61
- Sidekiq::Testing.inline!
62
- assert Sidekiq::Testing.enabled?
63
- assert Sidekiq::Testing.inline?
64
- refute Sidekiq::Testing.fake?
65
- end
66
-
67
- it 'enables inline testing in a block' do
68
- Sidekiq::Testing.disable!
69
- assert Sidekiq::Testing.disabled?
70
- refute Sidekiq::Testing.fake?
71
-
72
- Sidekiq::Testing.inline! do
73
- assert Sidekiq::Testing.enabled?
74
- assert Sidekiq::Testing.inline?
75
- end
76
-
77
- refute Sidekiq::Testing.enabled?
78
- refute Sidekiq::Testing.inline?
79
- refute Sidekiq::Testing.fake?
80
- end
81
- end
82
- end
83
-
84
- describe 'with middleware' do
85
- before do
86
- require 'sidekiq/testing'
87
- end
88
-
89
- after do
90
- Sidekiq::Testing.disable!
91
- end
92
-
93
- class AttributeWorker
94
- include Sidekiq::Worker
95
- class_attribute :count
96
- self.count = 0
97
- attr_accessor :foo
98
-
99
- def perform
100
- self.class.count += 1 if foo == :bar
101
- end
102
- end
103
-
104
- class AttributeMiddleware
105
- def call(worker, msg, queue)
106
- worker.foo = :bar if worker.respond_to?(:foo=)
107
- yield
108
- end
109
- end
110
-
111
- it 'wraps the inlined worker with middleware' do
112
- Sidekiq::Testing.server_middleware do |chain|
113
- chain.add AttributeMiddleware
114
- end
115
-
116
- begin
117
- Sidekiq::Testing.fake! do
118
- AttributeWorker.perform_async
119
- assert_equal 0, AttributeWorker.count
120
- end
121
-
122
- AttributeWorker.perform_one
123
- assert_equal 1, AttributeWorker.count
124
-
125
- Sidekiq::Testing.inline! do
126
- AttributeWorker.perform_async
127
- assert_equal 2, AttributeWorker.count
128
- end
129
- ensure
130
- Sidekiq::Testing.server_middleware.clear
131
- end
132
- end
133
- end
134
-
135
- end