sidekiq 3.5.0 → 3.5.1
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.
- checksums.yaml +4 -4
- data/COMM-LICENSE +1 -1
- data/Changes.md +9 -1
- data/Ent-Changes.md +14 -0
- data/Gemfile +1 -0
- data/Pro-Changes.md +12 -1
- data/bin/sidekiqload +153 -0
- data/lib/sidekiq.rb +13 -3
- data/lib/sidekiq/cli.rb +10 -10
- data/lib/sidekiq/manager.rb +1 -1
- data/lib/sidekiq/middleware/server/retry_jobs.rb +1 -1
- data/lib/sidekiq/processor.rb +14 -8
- data/lib/sidekiq/testing.rb +14 -5
- data/lib/sidekiq/version.rb +1 -1
- data/sidekiq.gemspec +1 -1
- data/test/test_api.rb +39 -50
- data/test/test_cli.rb +3 -57
- data/test/test_client.rb +60 -135
- data/test/test_extensions.rb +29 -23
- data/test/test_logging.rb +1 -1
- data/test/test_manager.rb +0 -1
- data/test/test_processor.rb +102 -31
- data/test/test_rails.rb +0 -2
- data/test/test_redis_connection.rb +0 -1
- data/test/test_retry.rb +85 -171
- data/test/test_scheduled.rb +7 -13
- data/test/test_scheduling.rb +20 -42
- data/test/test_sidekiq.rb +30 -18
- data/test/test_testing.rb +80 -20
- data/test/test_testing_fake.rb +4 -7
- data/test/test_testing_inline.rb +3 -3
- data/test/test_util.rb +0 -2
- data/test/test_web.rb +9 -2
- data/test/test_web_helpers.rb +3 -2
- data/web/locales/{no.yml → nb.yml} +10 -2
- data/web/locales/uk.yml +76 -0
- metadata +8 -6
data/test/test_scheduled.rb
CHANGED
@@ -10,11 +10,7 @@ class TestScheduled < Sidekiq::Test
|
|
10
10
|
|
11
11
|
describe 'poller' do
|
12
12
|
before do
|
13
|
-
Sidekiq.redis
|
14
|
-
Sidekiq.redis do |conn|
|
15
|
-
conn.flushdb
|
16
|
-
end
|
17
|
-
|
13
|
+
Sidekiq.redis{|c| c.flushdb}
|
18
14
|
@error_1 = { 'class' => ScheduledWorker.name, 'args' => [0], 'queue' => 'queue_1' }
|
19
15
|
@error_2 = { 'class' => ScheduledWorker.name, 'args' => [1], 'queue' => 'queue_2' }
|
20
16
|
@error_3 = { 'class' => ScheduledWorker.name, 'args' => [2], 'queue' => 'queue_3' }
|
@@ -28,8 +24,8 @@ class TestScheduled < Sidekiq::Test
|
|
28
24
|
end
|
29
25
|
|
30
26
|
class Stopper
|
31
|
-
def call(worker_class,
|
32
|
-
yield if
|
27
|
+
def call(worker_class, job, queue, r)
|
28
|
+
yield if job['args'].first.odd?
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
@@ -43,12 +39,10 @@ class TestScheduled < Sidekiq::Test
|
|
43
39
|
|
44
40
|
@poller.poll
|
45
41
|
|
46
|
-
Sidekiq.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
assert_equal 1, conn.llen("queue:queue_6")
|
51
|
-
end
|
42
|
+
assert_equal 0, Sidekiq::Queue.new("queue_1").size
|
43
|
+
assert_equal 1, Sidekiq::Queue.new("queue_2").size
|
44
|
+
assert_equal 0, Sidekiq::Queue.new("queue_5").size
|
45
|
+
assert_equal 1, Sidekiq::Queue.new("queue_6").size
|
52
46
|
ensure
|
53
47
|
Sidekiq.client_middleware.remove Stopper
|
54
48
|
end
|
data/test/test_scheduling.rb
CHANGED
@@ -3,20 +3,6 @@ require 'sidekiq/scheduled'
|
|
3
3
|
|
4
4
|
class TestScheduling < Sidekiq::Test
|
5
5
|
describe 'middleware' do
|
6
|
-
before do
|
7
|
-
Sidekiq::Client.instance_variable_set(:@default, nil)
|
8
|
-
@redis = Minitest::Mock.new
|
9
|
-
# Ugh, this is terrible.
|
10
|
-
Sidekiq.instance_variable_set(:@redis, @redis)
|
11
|
-
def @redis.multi; [yield] * 2 if block_given?; end
|
12
|
-
def @redis.with; yield self; end
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
Sidekiq::Client.instance_variable_set(:@default, nil)
|
17
|
-
Sidekiq.instance_variable_set(:@redis, REDIS)
|
18
|
-
end
|
19
|
-
|
20
6
|
class ScheduledWorker
|
21
7
|
include Sidekiq::Worker
|
22
8
|
sidekiq_options :queue => :custom_queue
|
@@ -24,47 +10,39 @@ class TestScheduling < Sidekiq::Test
|
|
24
10
|
end
|
25
11
|
end
|
26
12
|
|
27
|
-
it 'schedules
|
28
|
-
|
13
|
+
it 'schedules jobs' do
|
14
|
+
ss = Sidekiq::ScheduledSet.new
|
15
|
+
ss.clear
|
16
|
+
|
17
|
+
assert_equal 0, ss.size
|
18
|
+
|
29
19
|
assert ScheduledWorker.perform_in(600, 'mike')
|
30
|
-
|
31
|
-
end
|
20
|
+
assert_equal 1, ss.size
|
32
21
|
|
33
|
-
it 'schedules a job in one month' do
|
34
|
-
@redis.expect :zadd, true do |key, args|
|
35
|
-
assert_equal 'schedule', key
|
36
|
-
assert_in_delta 1.month.since.to_f, args[0][0].to_f, 1
|
37
|
-
end
|
38
22
|
assert ScheduledWorker.perform_in(1.month, 'mike')
|
39
|
-
|
40
|
-
end
|
23
|
+
assert_equal 2, ss.size
|
41
24
|
|
42
|
-
it 'schedules a job via timestamp' do
|
43
|
-
@redis.expect :zadd, true, ['schedule', Array]
|
44
25
|
assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
|
45
|
-
|
46
|
-
end
|
26
|
+
assert_equal 3, ss.size
|
47
27
|
|
48
|
-
|
49
|
-
|
50
|
-
@redis.expect :lpush, true, ['queue:custom_queue', Array]
|
28
|
+
q = Sidekiq::Queue.new("custom_queue")
|
29
|
+
qs = q.size
|
51
30
|
assert ScheduledWorker.perform_in(-300, 'mike')
|
52
|
-
|
53
|
-
|
31
|
+
assert_equal 3, ss.size
|
32
|
+
assert_equal qs+1, q.size
|
54
33
|
|
55
|
-
it 'schedules multiple jobs at once' do
|
56
|
-
@redis.expect :zadd, true, ['schedule', Array]
|
57
34
|
assert Sidekiq::Client.push_bulk('class' => ScheduledWorker, 'args' => [['mike'], ['mike']], 'at' => 600)
|
58
|
-
|
35
|
+
assert_equal 5, ss.size
|
59
36
|
end
|
60
37
|
|
61
38
|
it 'removes the enqueued_at field when scheduling' do
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
39
|
+
ss = Sidekiq::ScheduledSet.new
|
40
|
+
ss.clear
|
41
|
+
|
66
42
|
assert ScheduledWorker.perform_in(1.month, 'mike')
|
67
|
-
|
43
|
+
job = ss.first
|
44
|
+
assert job['created_at']
|
45
|
+
refute job['enqueued_at']
|
68
46
|
end
|
69
47
|
end
|
70
48
|
|
data/test/test_sidekiq.rb
CHANGED
@@ -3,24 +3,16 @@ require_relative 'helper'
|
|
3
3
|
|
4
4
|
class TestSidekiq < Sidekiq::Test
|
5
5
|
describe 'json processing' do
|
6
|
-
it '
|
7
|
-
assert_equal
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'dumps json' do
|
6
|
+
it 'handles json' do
|
7
|
+
assert_equal({"foo" => "bar"}, Sidekiq.load_json("{\"foo\":\"bar\"}"))
|
11
8
|
assert_equal "{\"foo\":\"bar\"}", Sidekiq.dump_json({ "foo" => "bar" })
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
15
12
|
describe "redis connection" do
|
16
13
|
it "returns error without creating a connection if block is not given" do
|
17
|
-
|
18
|
-
mock.expect :create, nil #Sidekiq::RedisConnection, create
|
19
|
-
assert_raises(ArgumentError) {
|
14
|
+
assert_raises(ArgumentError) do
|
20
15
|
Sidekiq.redis
|
21
|
-
}
|
22
|
-
assert_raises(MockExpectationError, "create should not be called") do
|
23
|
-
mock.verify
|
24
16
|
end
|
25
17
|
end
|
26
18
|
end
|
@@ -56,14 +48,14 @@ class TestSidekiq < Sidekiq::Test
|
|
56
48
|
end
|
57
49
|
|
58
50
|
describe 'default_worker_options' do
|
59
|
-
|
51
|
+
it 'stringifies keys' do
|
60
52
|
@old_options = Sidekiq.default_worker_options
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
53
|
+
begin
|
54
|
+
Sidekiq.default_worker_options = { queue: 'cat'}
|
55
|
+
assert_equal 'cat', Sidekiq.default_worker_options['queue']
|
56
|
+
ensure
|
57
|
+
Sidekiq.default_worker_options = @old_options
|
58
|
+
end
|
67
59
|
end
|
68
60
|
end
|
69
61
|
|
@@ -84,4 +76,24 @@ class TestSidekiq < Sidekiq::Test
|
|
84
76
|
assert_includes output, "ERROR"
|
85
77
|
end
|
86
78
|
end
|
79
|
+
|
80
|
+
describe 'redis connection' do
|
81
|
+
it 'does not continually retry' do
|
82
|
+
assert_raises Redis::CommandError do
|
83
|
+
Sidekiq.redis do |c|
|
84
|
+
raise Redis::CommandError, "READONLY You can't write against a read only slave."
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'reconnects if connection is flagged as readonly' do
|
90
|
+
counts = []
|
91
|
+
Sidekiq.redis do |c|
|
92
|
+
counts << c.info['total_connections_received'].to_i
|
93
|
+
raise Redis::CommandError, "READONLY You can't write against a read only slave." if counts.size == 1
|
94
|
+
end
|
95
|
+
assert_equal 2, counts.size
|
96
|
+
assert_equal counts[0] + 1, counts[1]
|
97
|
+
end
|
98
|
+
end
|
87
99
|
end
|
data/test/test_testing.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
-
|
3
|
-
require 'sidekiq/worker'
|
2
|
+
|
4
3
|
require 'active_record'
|
5
4
|
require 'action_mailer'
|
6
5
|
require 'sidekiq/rails'
|
@@ -13,7 +12,7 @@ class TestTesting < Sidekiq::Test
|
|
13
12
|
describe 'sidekiq testing' do
|
14
13
|
describe 'require/load sidekiq/testing.rb' do
|
15
14
|
before do
|
16
|
-
require 'sidekiq/testing
|
15
|
+
require 'sidekiq/testing'
|
17
16
|
end
|
18
17
|
|
19
18
|
after do
|
@@ -22,37 +21,43 @@ class TestTesting < Sidekiq::Test
|
|
22
21
|
|
23
22
|
it 'enables fake testing' do
|
24
23
|
Sidekiq::Testing.fake!
|
25
|
-
|
26
|
-
|
24
|
+
assert Sidekiq::Testing.enabled?
|
25
|
+
assert Sidekiq::Testing.fake?
|
26
|
+
refute Sidekiq::Testing.inline?
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'enables fake testing in a block' do
|
30
30
|
Sidekiq::Testing.disable!
|
31
|
-
|
31
|
+
assert Sidekiq::Testing.disabled?
|
32
|
+
refute Sidekiq::Testing.fake?
|
32
33
|
|
33
34
|
Sidekiq::Testing.fake! do
|
34
|
-
|
35
|
-
|
35
|
+
assert Sidekiq::Testing.enabled?
|
36
|
+
assert Sidekiq::Testing.fake?
|
37
|
+
refute Sidekiq::Testing.inline?
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
refute Sidekiq::Testing.enabled?
|
41
|
+
refute Sidekiq::Testing.fake?
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'disables testing in a block' do
|
43
45
|
Sidekiq::Testing.fake!
|
46
|
+
assert Sidekiq::Testing.fake?
|
44
47
|
|
45
48
|
Sidekiq::Testing.disable! do
|
46
|
-
|
49
|
+
refute Sidekiq::Testing.fake?
|
50
|
+
assert Sidekiq::Testing.disabled?
|
47
51
|
end
|
48
52
|
|
49
|
-
|
53
|
+
assert Sidekiq::Testing.fake?
|
54
|
+
assert Sidekiq::Testing.enabled?
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
53
58
|
describe 'require/load sidekiq/testing/inline.rb' do
|
54
59
|
before do
|
55
|
-
require 'sidekiq/testing/inline
|
60
|
+
require 'sidekiq/testing/inline'
|
56
61
|
end
|
57
62
|
|
58
63
|
after do
|
@@ -61,22 +66,77 @@ class TestTesting < Sidekiq::Test
|
|
61
66
|
|
62
67
|
it 'enables inline testing' do
|
63
68
|
Sidekiq::Testing.inline!
|
64
|
-
|
65
|
-
|
69
|
+
assert Sidekiq::Testing.enabled?
|
70
|
+
assert Sidekiq::Testing.inline?
|
71
|
+
refute Sidekiq::Testing.fake?
|
66
72
|
end
|
67
73
|
|
68
74
|
it 'enables inline testing in a block' do
|
69
75
|
Sidekiq::Testing.disable!
|
70
|
-
|
76
|
+
assert Sidekiq::Testing.disabled?
|
77
|
+
refute Sidekiq::Testing.fake?
|
71
78
|
|
72
79
|
Sidekiq::Testing.inline! do
|
73
|
-
|
74
|
-
|
80
|
+
assert Sidekiq::Testing.enabled?
|
81
|
+
assert Sidekiq::Testing.inline?
|
75
82
|
end
|
76
83
|
|
77
|
-
|
78
|
-
|
84
|
+
refute Sidekiq::Testing.enabled?
|
85
|
+
refute Sidekiq::Testing.inline?
|
86
|
+
refute Sidekiq::Testing.fake?
|
79
87
|
end
|
80
88
|
end
|
81
89
|
end
|
90
|
+
|
91
|
+
describe 'with middleware' do
|
92
|
+
before do
|
93
|
+
require 'sidekiq/testing'
|
94
|
+
end
|
95
|
+
|
96
|
+
after do
|
97
|
+
Sidekiq::Testing.disable!
|
98
|
+
end
|
99
|
+
|
100
|
+
class AttributeWorker
|
101
|
+
include Sidekiq::Worker
|
102
|
+
class_attribute :count
|
103
|
+
self.count = 0
|
104
|
+
attr_accessor :foo
|
105
|
+
|
106
|
+
def perform
|
107
|
+
self.class.count += 1 if foo == :bar
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class AttributeMiddleware
|
112
|
+
def call(worker, msg, queue)
|
113
|
+
worker.foo = :bar if worker.respond_to?(:foo=)
|
114
|
+
yield
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'wraps the inlined worker with middleware' do
|
119
|
+
Sidekiq::Testing.server_middleware do |chain|
|
120
|
+
chain.add AttributeMiddleware
|
121
|
+
end
|
122
|
+
|
123
|
+
begin
|
124
|
+
Sidekiq::Testing.fake! do
|
125
|
+
AttributeWorker.perform_async
|
126
|
+
assert_equal 0, AttributeWorker.count
|
127
|
+
end
|
128
|
+
|
129
|
+
AttributeWorker.perform_one
|
130
|
+
assert_equal 1, AttributeWorker.count
|
131
|
+
|
132
|
+
Sidekiq::Testing.inline! do
|
133
|
+
AttributeWorker.perform_async
|
134
|
+
assert_equal 2, AttributeWorker.count
|
135
|
+
end
|
136
|
+
ensure
|
137
|
+
Sidekiq::Testing.server_middleware.clear
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
82
142
|
end
|
data/test/test_testing_fake.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
-
|
3
|
-
require 'sidekiq/worker'
|
2
|
+
|
4
3
|
require 'active_record'
|
5
4
|
require 'action_mailer'
|
6
5
|
require 'sidekiq/rails'
|
@@ -47,7 +46,7 @@ class TestTesting < Sidekiq::Test
|
|
47
46
|
end
|
48
47
|
|
49
48
|
before do
|
50
|
-
require 'sidekiq/testing
|
49
|
+
require 'sidekiq/testing'
|
51
50
|
Sidekiq::Testing.fake!
|
52
51
|
EnqueuedWorker.jobs.clear
|
53
52
|
DirectWorker.jobs.clear
|
@@ -106,7 +105,6 @@ class TestTesting < Sidekiq::Test
|
|
106
105
|
StoredWorker.drain
|
107
106
|
end
|
108
107
|
assert_equal 0, StoredWorker.jobs.size
|
109
|
-
|
110
108
|
end
|
111
109
|
|
112
110
|
class SpecificJidWorker
|
@@ -263,9 +261,8 @@ class TestTesting < Sidekiq::Test
|
|
263
261
|
end
|
264
262
|
|
265
263
|
it 'can execute a job' do
|
266
|
-
|
267
|
-
worker.expect(:perform, nil, [1, 2, 3])
|
268
|
-
DirectWorker.execute_job(worker, [1, 2, 3])
|
264
|
+
DirectWorker.execute_job(DirectWorker.new, [2, 3])
|
269
265
|
end
|
266
|
+
|
270
267
|
end
|
271
268
|
end
|
data/test/test_testing_inline.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
-
|
3
|
-
require 'sidekiq/worker'
|
2
|
+
|
4
3
|
require 'active_record'
|
5
4
|
require 'action_mailer'
|
6
5
|
require 'sidekiq/rails'
|
@@ -42,7 +41,7 @@ class TestInline < Sidekiq::Test
|
|
42
41
|
end
|
43
42
|
|
44
43
|
before do
|
45
|
-
require 'sidekiq/testing/inline
|
44
|
+
require 'sidekiq/testing/inline'
|
46
45
|
Sidekiq::Testing.inline!
|
47
46
|
end
|
48
47
|
|
@@ -89,5 +88,6 @@ class TestInline < Sidekiq::Test
|
|
89
88
|
it 'should relay parameters through json' do
|
90
89
|
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now)
|
91
90
|
end
|
91
|
+
|
92
92
|
end
|
93
93
|
end
|
data/test/test_util.rb
CHANGED
data/test/test_web.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require_relative 'helper'
|
3
|
-
require 'sidekiq'
|
4
3
|
require 'sidekiq/web'
|
5
4
|
require 'rack/test'
|
6
5
|
require 'tilt/erubis'
|
@@ -19,7 +18,6 @@ class TestWeb < Sidekiq::Test
|
|
19
18
|
end
|
20
19
|
|
21
20
|
before do
|
22
|
-
Sidekiq.redis = REDIS
|
23
21
|
Sidekiq.redis {|c| c.flushdb }
|
24
22
|
end
|
25
23
|
|
@@ -41,6 +39,15 @@ class TestWeb < Sidekiq::Test
|
|
41
39
|
rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'en-us'}
|
42
40
|
get '/', {}, rackenv
|
43
41
|
assert_match(/Dashboard/, last_response.body)
|
42
|
+
rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'zh-cn'}
|
43
|
+
get '/', {}, rackenv
|
44
|
+
assert_match(/信息板/, last_response.body)
|
45
|
+
rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'zh-tw'}
|
46
|
+
get '/', {}, rackenv
|
47
|
+
assert_match(/資訊主頁/, last_response.body)
|
48
|
+
rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'nb'}
|
49
|
+
get '/', {}, rackenv
|
50
|
+
assert_match(/Oversikt/, last_response.body)
|
44
51
|
end
|
45
52
|
|
46
53
|
describe 'busy' do
|