sidekiq 4.2.4 → 5.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.
- checksums.yaml +5 -5
- data/.circleci/config.yml +61 -0
- data/.github/issue_template.md +8 -1
- data/.gitignore +3 -0
- data/.travis.yml +5 -6
- data/5.0-Upgrade.md +56 -0
- data/COMM-LICENSE +12 -10
- data/Changes.md +220 -0
- data/Ent-Changes.md +94 -2
- data/Gemfile +12 -22
- data/LICENSE +1 -1
- data/Pro-4.0-Upgrade.md +35 -0
- data/Pro-Changes.md +176 -2
- data/README.md +10 -7
- data/Rakefile +3 -3
- data/bin/sidekiqctl +13 -92
- data/bin/sidekiqload +16 -34
- data/lib/generators/sidekiq/templates/worker_spec.rb.erb +1 -1
- data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
- data/lib/sidekiq/api.rb +166 -68
- data/lib/sidekiq/cli.rb +122 -77
- data/lib/sidekiq/client.rb +25 -18
- data/lib/sidekiq/core_ext.rb +1 -106
- data/lib/sidekiq/ctl.rb +221 -0
- data/lib/sidekiq/delay.rb +42 -0
- data/lib/sidekiq/exception_handler.rb +2 -4
- data/lib/sidekiq/extensions/generic_proxy.rb +7 -1
- data/lib/sidekiq/fetch.rb +1 -1
- data/lib/sidekiq/job_logger.rb +25 -0
- data/lib/sidekiq/job_retry.rb +262 -0
- data/lib/sidekiq/launcher.rb +49 -40
- data/lib/sidekiq/logging.rb +18 -2
- data/lib/sidekiq/manager.rb +6 -7
- data/lib/sidekiq/middleware/server/active_record.rb +10 -0
- data/lib/sidekiq/processor.rb +127 -37
- data/lib/sidekiq/rails.rb +16 -51
- data/lib/sidekiq/redis_connection.rb +50 -5
- data/lib/sidekiq/scheduled.rb +35 -8
- data/lib/sidekiq/testing.rb +24 -7
- data/lib/sidekiq/util.rb +6 -2
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/action.rb +3 -7
- data/lib/sidekiq/web/application.rb +38 -22
- data/lib/sidekiq/web/helpers.rb +78 -27
- data/lib/sidekiq/web/router.rb +14 -10
- data/lib/sidekiq/web.rb +4 -4
- data/lib/sidekiq/worker.rb +118 -19
- data/lib/sidekiq.rb +27 -26
- data/sidekiq.gemspec +8 -13
- data/web/assets/javascripts/application.js +0 -0
- data/web/assets/javascripts/dashboard.js +33 -18
- data/web/assets/stylesheets/application-rtl.css +246 -0
- data/web/assets/stylesheets/application.css +371 -6
- data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
- data/web/assets/stylesheets/bootstrap.css +2 -2
- data/web/locales/ar.yml +81 -0
- data/web/locales/en.yml +2 -0
- data/web/locales/es.yml +4 -3
- data/web/locales/fa.yml +80 -0
- data/web/locales/he.yml +79 -0
- data/web/locales/ja.yml +5 -3
- data/web/locales/ur.yml +80 -0
- data/web/views/_footer.erb +5 -2
- data/web/views/_job_info.erb +1 -1
- data/web/views/_nav.erb +4 -18
- data/web/views/_paging.erb +1 -1
- data/web/views/busy.erb +9 -5
- data/web/views/dashboard.erb +3 -3
- data/web/views/layout.erb +11 -2
- data/web/views/morgue.erb +14 -10
- data/web/views/queue.erb +11 -10
- data/web/views/queues.erb +4 -2
- data/web/views/retries.erb +17 -11
- data/web/views/retry.erb +1 -1
- data/web/views/scheduled.erb +2 -2
- metadata +32 -151
- data/lib/sidekiq/middleware/server/logging.rb +0 -40
- data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -205
- data/test/config.yml +0 -9
- data/test/env_based_config.yml +0 -11
- data/test/fake_env.rb +0 -1
- data/test/fixtures/en.yml +0 -2
- data/test/helper.rb +0 -75
- data/test/test_actors.rb +0 -138
- data/test/test_api.rb +0 -528
- data/test/test_cli.rb +0 -418
- data/test/test_client.rb +0 -266
- data/test/test_exception_handler.rb +0 -56
- data/test/test_extensions.rb +0 -127
- data/test/test_fetch.rb +0 -50
- data/test/test_launcher.rb +0 -95
- data/test/test_logging.rb +0 -35
- data/test/test_manager.rb +0 -50
- data/test/test_middleware.rb +0 -158
- data/test/test_processor.rb +0 -235
- data/test/test_rails.rb +0 -22
- data/test/test_redis_connection.rb +0 -132
- data/test/test_retry.rb +0 -326
- data/test/test_retry_exhausted.rb +0 -149
- data/test/test_scheduled.rb +0 -115
- data/test/test_scheduling.rb +0 -58
- data/test/test_sidekiq.rb +0 -107
- data/test/test_testing.rb +0 -143
- data/test/test_testing_fake.rb +0 -357
- data/test/test_testing_inline.rb +0 -94
- data/test/test_util.rb +0 -13
- data/test/test_web.rb +0 -726
- data/test/test_web_helpers.rb +0 -54
data/test/test_sidekiq.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
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
|
data/test/test_testing.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
require 'active_record'
|
5
|
-
require 'action_mailer'
|
6
|
-
require 'sidekiq/rails'
|
7
|
-
require 'sidekiq/extensions/action_mailer'
|
8
|
-
require 'sidekiq/extensions/active_record'
|
9
|
-
|
10
|
-
Sidekiq.hook_rails!
|
11
|
-
|
12
|
-
class TestTesting < Sidekiq::Test
|
13
|
-
describe 'sidekiq testing' do
|
14
|
-
describe 'require/load sidekiq/testing.rb' do
|
15
|
-
before do
|
16
|
-
require 'sidekiq/testing'
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
Sidekiq::Testing.disable!
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'enables fake testing' do
|
24
|
-
Sidekiq::Testing.fake!
|
25
|
-
assert Sidekiq::Testing.enabled?
|
26
|
-
assert Sidekiq::Testing.fake?
|
27
|
-
refute Sidekiq::Testing.inline?
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'enables fake testing in a block' do
|
31
|
-
Sidekiq::Testing.disable!
|
32
|
-
assert Sidekiq::Testing.disabled?
|
33
|
-
refute Sidekiq::Testing.fake?
|
34
|
-
|
35
|
-
Sidekiq::Testing.fake! do
|
36
|
-
assert Sidekiq::Testing.enabled?
|
37
|
-
assert Sidekiq::Testing.fake?
|
38
|
-
refute Sidekiq::Testing.inline?
|
39
|
-
end
|
40
|
-
|
41
|
-
refute Sidekiq::Testing.enabled?
|
42
|
-
refute Sidekiq::Testing.fake?
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'disables testing in a block' do
|
46
|
-
Sidekiq::Testing.fake!
|
47
|
-
assert Sidekiq::Testing.fake?
|
48
|
-
|
49
|
-
Sidekiq::Testing.disable! do
|
50
|
-
refute Sidekiq::Testing.fake?
|
51
|
-
assert Sidekiq::Testing.disabled?
|
52
|
-
end
|
53
|
-
|
54
|
-
assert Sidekiq::Testing.fake?
|
55
|
-
assert Sidekiq::Testing.enabled?
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'require/load sidekiq/testing/inline.rb' do
|
60
|
-
before do
|
61
|
-
require 'sidekiq/testing/inline'
|
62
|
-
end
|
63
|
-
|
64
|
-
after do
|
65
|
-
Sidekiq::Testing.disable!
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'enables inline testing' do
|
69
|
-
Sidekiq::Testing.inline!
|
70
|
-
assert Sidekiq::Testing.enabled?
|
71
|
-
assert Sidekiq::Testing.inline?
|
72
|
-
refute Sidekiq::Testing.fake?
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'enables inline testing in a block' do
|
76
|
-
Sidekiq::Testing.disable!
|
77
|
-
assert Sidekiq::Testing.disabled?
|
78
|
-
refute Sidekiq::Testing.fake?
|
79
|
-
|
80
|
-
Sidekiq::Testing.inline! do
|
81
|
-
assert Sidekiq::Testing.enabled?
|
82
|
-
assert Sidekiq::Testing.inline?
|
83
|
-
end
|
84
|
-
|
85
|
-
refute Sidekiq::Testing.enabled?
|
86
|
-
refute Sidekiq::Testing.inline?
|
87
|
-
refute Sidekiq::Testing.fake?
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe 'with middleware' do
|
93
|
-
before do
|
94
|
-
require 'sidekiq/testing'
|
95
|
-
end
|
96
|
-
|
97
|
-
after do
|
98
|
-
Sidekiq::Testing.disable!
|
99
|
-
end
|
100
|
-
|
101
|
-
class AttributeWorker
|
102
|
-
include Sidekiq::Worker
|
103
|
-
class_attribute :count
|
104
|
-
self.count = 0
|
105
|
-
attr_accessor :foo
|
106
|
-
|
107
|
-
def perform
|
108
|
-
self.class.count += 1 if foo == :bar
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
class AttributeMiddleware
|
113
|
-
def call(worker, msg, queue)
|
114
|
-
worker.foo = :bar if worker.respond_to?(:foo=)
|
115
|
-
yield
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'wraps the inlined worker with middleware' do
|
120
|
-
Sidekiq::Testing.server_middleware do |chain|
|
121
|
-
chain.add AttributeMiddleware
|
122
|
-
end
|
123
|
-
|
124
|
-
begin
|
125
|
-
Sidekiq::Testing.fake! do
|
126
|
-
AttributeWorker.perform_async
|
127
|
-
assert_equal 0, AttributeWorker.count
|
128
|
-
end
|
129
|
-
|
130
|
-
AttributeWorker.perform_one
|
131
|
-
assert_equal 1, AttributeWorker.count
|
132
|
-
|
133
|
-
Sidekiq::Testing.inline! do
|
134
|
-
AttributeWorker.perform_async
|
135
|
-
assert_equal 2, AttributeWorker.count
|
136
|
-
end
|
137
|
-
ensure
|
138
|
-
Sidekiq::Testing.server_middleware.clear
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
data/test/test_testing_fake.rb
DELETED
@@ -1,357 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
require 'active_record'
|
5
|
-
require 'action_mailer'
|
6
|
-
require 'sidekiq/rails'
|
7
|
-
require 'sidekiq/extensions/action_mailer'
|
8
|
-
require 'sidekiq/extensions/active_record'
|
9
|
-
|
10
|
-
Sidekiq.hook_rails!
|
11
|
-
|
12
|
-
class TestTesting < Sidekiq::Test
|
13
|
-
describe 'sidekiq testing' do
|
14
|
-
class PerformError < RuntimeError; end
|
15
|
-
|
16
|
-
class DirectWorker
|
17
|
-
include Sidekiq::Worker
|
18
|
-
def perform(a, b)
|
19
|
-
a + b
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class EnqueuedWorker
|
24
|
-
include Sidekiq::Worker
|
25
|
-
def perform(a, b)
|
26
|
-
a + b
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class StoredWorker
|
31
|
-
include Sidekiq::Worker
|
32
|
-
def perform(error)
|
33
|
-
raise PerformError if error
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class FooMailer < ActionMailer::Base
|
38
|
-
def bar(str)
|
39
|
-
str
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class FooModel < ActiveRecord::Base
|
44
|
-
def bar(str)
|
45
|
-
str
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
before do
|
50
|
-
require 'sidekiq/testing'
|
51
|
-
Sidekiq::Testing.fake!
|
52
|
-
EnqueuedWorker.jobs.clear
|
53
|
-
DirectWorker.jobs.clear
|
54
|
-
end
|
55
|
-
|
56
|
-
after do
|
57
|
-
Sidekiq::Testing.disable!
|
58
|
-
Sidekiq::Queues.clear_all
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'stubs the async call' do
|
62
|
-
assert_equal 0, DirectWorker.jobs.size
|
63
|
-
assert DirectWorker.perform_async(1, 2)
|
64
|
-
assert_equal 1, DirectWorker.jobs.size
|
65
|
-
assert DirectWorker.perform_in(10, 1, 2)
|
66
|
-
assert_equal 2, DirectWorker.jobs.size
|
67
|
-
assert DirectWorker.perform_at(10, 1, 2)
|
68
|
-
assert_equal 3, DirectWorker.jobs.size
|
69
|
-
assert_in_delta 10.seconds.from_now.to_f, DirectWorker.jobs.last['at'], 0.01
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'stubs the delay call on mailers' do
|
73
|
-
assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
|
74
|
-
FooMailer.delay.bar('hello!')
|
75
|
-
assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
|
76
|
-
end
|
77
|
-
|
78
|
-
class Something
|
79
|
-
def self.foo(x)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'stubs the delay call on models' do
|
84
|
-
assert_equal 0, Sidekiq::Extensions::DelayedClass.jobs.size
|
85
|
-
Something.delay.foo(Date.today)
|
86
|
-
assert_equal 1, Sidekiq::Extensions::DelayedClass.jobs.size
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'stubs the enqueue call' do
|
90
|
-
assert_equal 0, EnqueuedWorker.jobs.size
|
91
|
-
assert Sidekiq::Client.enqueue(EnqueuedWorker, 1, 2)
|
92
|
-
assert_equal 1, EnqueuedWorker.jobs.size
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'stubs the enqueue_to call' do
|
96
|
-
assert_equal 0, EnqueuedWorker.jobs.size
|
97
|
-
assert Sidekiq::Client.enqueue_to('someq', EnqueuedWorker, 1, 2)
|
98
|
-
assert_equal 1, Sidekiq::Queues['someq'].size
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'executes all stored jobs' do
|
102
|
-
assert StoredWorker.perform_async(false)
|
103
|
-
assert StoredWorker.perform_async(true)
|
104
|
-
|
105
|
-
assert_equal 2, StoredWorker.jobs.size
|
106
|
-
assert_raises PerformError do
|
107
|
-
StoredWorker.drain
|
108
|
-
end
|
109
|
-
assert_equal 0, StoredWorker.jobs.size
|
110
|
-
end
|
111
|
-
|
112
|
-
class SpecificJidWorker
|
113
|
-
include Sidekiq::Worker
|
114
|
-
class_attribute :count
|
115
|
-
self.count = 0
|
116
|
-
def perform(worker_jid)
|
117
|
-
return unless worker_jid == self.jid
|
118
|
-
self.class.count += 1
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'execute only jobs with assigned JID' do
|
123
|
-
4.times do |i|
|
124
|
-
jid = SpecificJidWorker.perform_async(nil)
|
125
|
-
if i % 2 == 0
|
126
|
-
SpecificJidWorker.jobs[-1]["args"] = ["wrong_jid"]
|
127
|
-
else
|
128
|
-
SpecificJidWorker.jobs[-1]["args"] = [jid]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
SpecificJidWorker.perform_one
|
133
|
-
assert_equal 0, SpecificJidWorker.count
|
134
|
-
|
135
|
-
SpecificJidWorker.perform_one
|
136
|
-
assert_equal 1, SpecificJidWorker.count
|
137
|
-
|
138
|
-
SpecificJidWorker.drain
|
139
|
-
assert_equal 2, SpecificJidWorker.count
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'round trip serializes the job arguments' do
|
143
|
-
assert StoredWorker.perform_async(:mike)
|
144
|
-
job = StoredWorker.jobs.first
|
145
|
-
assert_equal "mike", job['args'].first
|
146
|
-
StoredWorker.clear
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'perform_one runs only one job' do
|
150
|
-
DirectWorker.perform_async(1, 2)
|
151
|
-
DirectWorker.perform_async(3, 4)
|
152
|
-
assert_equal 2, DirectWorker.jobs.size
|
153
|
-
|
154
|
-
DirectWorker.perform_one
|
155
|
-
assert_equal 1, DirectWorker.jobs.size
|
156
|
-
|
157
|
-
DirectWorker.clear
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'perform_one raise error upon empty queue' do
|
161
|
-
DirectWorker.clear
|
162
|
-
assert_raises Sidekiq::EmptyQueueError do
|
163
|
-
DirectWorker.perform_one
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
class FirstWorker
|
168
|
-
include Sidekiq::Worker
|
169
|
-
class_attribute :count
|
170
|
-
self.count = 0
|
171
|
-
def perform
|
172
|
-
self.class.count += 1
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class SecondWorker
|
177
|
-
include Sidekiq::Worker
|
178
|
-
class_attribute :count
|
179
|
-
self.count = 0
|
180
|
-
def perform
|
181
|
-
self.class.count += 1
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
class ThirdWorker
|
186
|
-
include Sidekiq::Worker
|
187
|
-
class_attribute :count
|
188
|
-
def perform
|
189
|
-
FirstWorker.perform_async
|
190
|
-
SecondWorker.perform_async
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
it 'clears jobs across all workers' do
|
195
|
-
Sidekiq::Worker.jobs.clear
|
196
|
-
FirstWorker.count = 0
|
197
|
-
SecondWorker.count = 0
|
198
|
-
|
199
|
-
assert_equal 0, FirstWorker.jobs.size
|
200
|
-
assert_equal 0, SecondWorker.jobs.size
|
201
|
-
|
202
|
-
FirstWorker.perform_async
|
203
|
-
SecondWorker.perform_async
|
204
|
-
|
205
|
-
assert_equal 1, FirstWorker.jobs.size
|
206
|
-
assert_equal 1, SecondWorker.jobs.size
|
207
|
-
|
208
|
-
Sidekiq::Worker.clear_all
|
209
|
-
|
210
|
-
assert_equal 0, FirstWorker.jobs.size
|
211
|
-
assert_equal 0, SecondWorker.jobs.size
|
212
|
-
|
213
|
-
assert_equal 0, FirstWorker.count
|
214
|
-
assert_equal 0, SecondWorker.count
|
215
|
-
end
|
216
|
-
|
217
|
-
it 'drains jobs across all workers' do
|
218
|
-
Sidekiq::Worker.jobs.clear
|
219
|
-
FirstWorker.count = 0
|
220
|
-
SecondWorker.count = 0
|
221
|
-
|
222
|
-
assert_equal 0, FirstWorker.jobs.size
|
223
|
-
assert_equal 0, SecondWorker.jobs.size
|
224
|
-
|
225
|
-
assert_equal 0, FirstWorker.count
|
226
|
-
assert_equal 0, SecondWorker.count
|
227
|
-
|
228
|
-
FirstWorker.perform_async
|
229
|
-
SecondWorker.perform_async
|
230
|
-
|
231
|
-
assert_equal 1, FirstWorker.jobs.size
|
232
|
-
assert_equal 1, SecondWorker.jobs.size
|
233
|
-
|
234
|
-
Sidekiq::Worker.drain_all
|
235
|
-
|
236
|
-
assert_equal 0, FirstWorker.jobs.size
|
237
|
-
assert_equal 0, SecondWorker.jobs.size
|
238
|
-
|
239
|
-
assert_equal 1, FirstWorker.count
|
240
|
-
assert_equal 1, SecondWorker.count
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'drains jobs across all workers even when workers create new jobs' do
|
244
|
-
Sidekiq::Worker.jobs.clear
|
245
|
-
FirstWorker.count = 0
|
246
|
-
SecondWorker.count = 0
|
247
|
-
|
248
|
-
assert_equal 0, ThirdWorker.jobs.size
|
249
|
-
|
250
|
-
assert_equal 0, FirstWorker.count
|
251
|
-
assert_equal 0, SecondWorker.count
|
252
|
-
|
253
|
-
ThirdWorker.perform_async
|
254
|
-
|
255
|
-
assert_equal 1, ThirdWorker.jobs.size
|
256
|
-
|
257
|
-
Sidekiq::Worker.drain_all
|
258
|
-
|
259
|
-
assert_equal 0, ThirdWorker.jobs.size
|
260
|
-
|
261
|
-
assert_equal 1, FirstWorker.count
|
262
|
-
assert_equal 1, SecondWorker.count
|
263
|
-
end
|
264
|
-
|
265
|
-
it 'drains jobs of workers with symbolized queue names' do
|
266
|
-
Sidekiq::Worker.jobs.clear
|
267
|
-
|
268
|
-
AltQueueWorker.perform_async(5,6)
|
269
|
-
assert_equal 1, AltQueueWorker.jobs.size
|
270
|
-
|
271
|
-
Sidekiq::Worker.drain_all
|
272
|
-
assert_equal 0, AltQueueWorker.jobs.size
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'can execute a job' do
|
276
|
-
DirectWorker.execute_job(DirectWorker.new, [2, 3])
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
describe 'queue testing' do
|
281
|
-
before do
|
282
|
-
require 'sidekiq/testing'
|
283
|
-
Sidekiq::Testing.fake!
|
284
|
-
end
|
285
|
-
|
286
|
-
after do
|
287
|
-
Sidekiq::Testing.disable!
|
288
|
-
Sidekiq::Queues.clear_all
|
289
|
-
end
|
290
|
-
|
291
|
-
class QueueWorker
|
292
|
-
include Sidekiq::Worker
|
293
|
-
def perform(a, b)
|
294
|
-
a + b
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
class AltQueueWorker
|
299
|
-
include Sidekiq::Worker
|
300
|
-
sidekiq_options queue: :alt
|
301
|
-
def perform(a, b)
|
302
|
-
a + b
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
it 'finds enqueued jobs' do
|
307
|
-
assert_equal 0, Sidekiq::Queues["default"].size
|
308
|
-
|
309
|
-
QueueWorker.perform_async(1, 2)
|
310
|
-
QueueWorker.perform_async(1, 2)
|
311
|
-
AltQueueWorker.perform_async(1, 2)
|
312
|
-
|
313
|
-
assert_equal 2, Sidekiq::Queues["default"].size
|
314
|
-
assert_equal [1, 2], Sidekiq::Queues["default"].first["args"]
|
315
|
-
|
316
|
-
assert_equal 1, Sidekiq::Queues["alt"].size
|
317
|
-
end
|
318
|
-
|
319
|
-
it 'clears out all queues' do
|
320
|
-
assert_equal 0, Sidekiq::Queues["default"].size
|
321
|
-
|
322
|
-
QueueWorker.perform_async(1, 2)
|
323
|
-
QueueWorker.perform_async(1, 2)
|
324
|
-
AltQueueWorker.perform_async(1, 2)
|
325
|
-
|
326
|
-
Sidekiq::Queues.clear_all
|
327
|
-
|
328
|
-
assert_equal 0, Sidekiq::Queues["default"].size
|
329
|
-
assert_equal 0, QueueWorker.jobs.size
|
330
|
-
assert_equal 0, Sidekiq::Queues["alt"].size
|
331
|
-
assert_equal 0, AltQueueWorker.jobs.size
|
332
|
-
end
|
333
|
-
|
334
|
-
it 'finds jobs enqueued by client' do
|
335
|
-
Sidekiq::Client.push(
|
336
|
-
'class' => 'NonExistentWorker',
|
337
|
-
'queue' => 'missing',
|
338
|
-
'args' => [1]
|
339
|
-
)
|
340
|
-
|
341
|
-
assert_equal 1, Sidekiq::Queues["missing"].size
|
342
|
-
end
|
343
|
-
|
344
|
-
it 'respects underlying array changes' do
|
345
|
-
# Rspec expect change() syntax saves a reference to
|
346
|
-
# an underlying array. When the array containing jobs is
|
347
|
-
# derived, Rspec test using `change(QueueWorker.jobs, :size).by(1)`
|
348
|
-
# won't pass. This attempts to recreate that scenario
|
349
|
-
# by saving a reference to the jobs array and ensuring
|
350
|
-
# it changes properly on enqueueing
|
351
|
-
jobs = QueueWorker.jobs
|
352
|
-
assert_equal 0, jobs.size
|
353
|
-
QueueWorker.perform_async(1, 2)
|
354
|
-
assert_equal 1, jobs.size
|
355
|
-
end
|
356
|
-
end
|
357
|
-
end
|
data/test/test_testing_inline.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
require 'active_record'
|
5
|
-
require 'action_mailer'
|
6
|
-
require 'sidekiq/rails'
|
7
|
-
require 'sidekiq/extensions/action_mailer'
|
8
|
-
require 'sidekiq/extensions/active_record'
|
9
|
-
|
10
|
-
Sidekiq.hook_rails!
|
11
|
-
|
12
|
-
class TestInline < Sidekiq::Test
|
13
|
-
describe 'sidekiq inline testing' do
|
14
|
-
class InlineError < RuntimeError; end
|
15
|
-
class ParameterIsNotString < RuntimeError; end
|
16
|
-
|
17
|
-
class InlineWorker
|
18
|
-
include Sidekiq::Worker
|
19
|
-
def perform(pass)
|
20
|
-
raise ArgumentError, "no jid" unless jid
|
21
|
-
raise InlineError unless pass
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class InlineWorkerWithTimeParam
|
26
|
-
include Sidekiq::Worker
|
27
|
-
def perform(time)
|
28
|
-
raise ParameterIsNotString unless time.is_a?(String) || time.is_a?(Numeric)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class InlineFooMailer < ActionMailer::Base
|
33
|
-
def bar(str)
|
34
|
-
raise InlineError
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class InlineFooModel < ActiveRecord::Base
|
39
|
-
def self.bar(str)
|
40
|
-
raise InlineError
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
before do
|
45
|
-
require 'sidekiq/testing/inline'
|
46
|
-
Sidekiq::Testing.inline!
|
47
|
-
end
|
48
|
-
|
49
|
-
after do
|
50
|
-
Sidekiq::Testing.disable!
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'stubs the async call when in testing mode' do
|
54
|
-
assert InlineWorker.perform_async(true)
|
55
|
-
|
56
|
-
assert_raises InlineError do
|
57
|
-
InlineWorker.perform_async(false)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'stubs the delay call on mailers' do
|
62
|
-
assert_raises InlineError do
|
63
|
-
InlineFooMailer.delay.bar('three')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'stubs the delay call on models' do
|
68
|
-
assert_raises InlineError do
|
69
|
-
InlineFooModel.delay.bar('three')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'stubs the enqueue call when in testing mode' do
|
74
|
-
assert Sidekiq::Client.enqueue(InlineWorker, true)
|
75
|
-
|
76
|
-
assert_raises InlineError do
|
77
|
-
Sidekiq::Client.enqueue(InlineWorker, false)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'stubs the push_bulk call when in testing mode' do
|
82
|
-
assert Sidekiq::Client.push_bulk({'class' => InlineWorker, 'args' => [[true], [true]]})
|
83
|
-
|
84
|
-
assert_raises InlineError do
|
85
|
-
Sidekiq::Client.push_bulk({'class' => InlineWorker, 'args' => [[true], [false]]})
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should relay parameters through json' do
|
90
|
-
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now.to_f)
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|