sidekiq-unique-jobs 5.0.2 → 5.0.11
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq-unique-jobs might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +8 -0
- data/.rubocop.yml +20 -13
- data/.simplecov +1 -1
- data/.travis.yml +30 -20
- data/Appraisals +10 -2
- data/CHANGELOG.md +33 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -12
- data/LICENSE.txt +21 -0
- data/README.md +48 -4
- data/Rakefile +0 -1
- data/bin/bench +1 -1
- data/lib/sidekiq/simulator.rb +4 -10
- data/lib/sidekiq-unique-jobs.rb +16 -6
- data/lib/sidekiq_unique_jobs/cli.rb +14 -12
- data/lib/sidekiq_unique_jobs/client/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/config.rb +2 -0
- data/lib/sidekiq_unique_jobs/constants.rb +20 -17
- data/lib/sidekiq_unique_jobs/core_ext.rb +18 -0
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +4 -5
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/until_timeout.rb +2 -0
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +10 -9
- data/lib/sidekiq_unique_jobs/lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/normalizer.rb +3 -1
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +22 -3
- data/lib/sidekiq_unique_jobs/run_lock_failed.rb +2 -0
- data/lib/sidekiq_unique_jobs/script_mock.rb +16 -15
- data/lib/sidekiq_unique_jobs/scripts/acquire_lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/scripts/release_lock.rb +2 -0
- data/lib/sidekiq_unique_jobs/scripts.rb +17 -12
- data/lib/sidekiq_unique_jobs/server/middleware.rb +2 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +4 -14
- data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +2 -0
- data/lib/sidekiq_unique_jobs/testing.rb +4 -2
- data/lib/sidekiq_unique_jobs/timeout_calculator.rb +2 -0
- data/lib/sidekiq_unique_jobs/unique_args.rb +27 -14
- data/lib/sidekiq_unique_jobs/unlockable.rb +6 -6
- data/lib/sidekiq_unique_jobs/util.rb +34 -14
- data/lib/sidekiq_unique_jobs/version.rb +3 -1
- data/redis/acquire_lock.lua +1 -1
- data/sidekiq-unique-jobs.gemspec +27 -23
- metadata +44 -212
- data/LICENSE +0 -13
- data/circle.yml +0 -41
- data/gemfiles/sidekiq_4.0.gemfile +0 -22
- data/gemfiles/sidekiq_4.1.gemfile +0 -22
- data/gemfiles/sidekiq_4.2.gemfile +0 -22
- data/gemfiles/sidekiq_5.0.gemfile +0 -22
- data/gemfiles/sidekiq_develop.gemfile +0 -22
- data/rails_example/.env +0 -12
- data/rails_example/.env.test +0 -12
- data/rails_example/.gitignore +0 -13
- data/rails_example/.rspec +0 -2
- data/rails_example/Gemfile +0 -38
- data/rails_example/Procfile +0 -2
- data/rails_example/README.rdoc +0 -28
- data/rails_example/Rakefile +0 -6
- data/rails_example/app/assets/images/.keep +0 -0
- data/rails_example/app/assets/javascripts/application.js +0 -16
- data/rails_example/app/assets/stylesheets/application.css +0 -15
- data/rails_example/app/channels/appearance_channel.rb +0 -17
- data/rails_example/app/channels/application_cable/channel.rb +0 -4
- data/rails_example/app/channels/application_cable/connection.rb +0 -9
- data/rails_example/app/channels/post_channel.rb +0 -5
- data/rails_example/app/controllers/application_controller.rb +0 -5
- data/rails_example/app/controllers/concerns/.keep +0 -0
- data/rails_example/app/controllers/work_controller.rb +0 -39
- data/rails_example/app/helpers/application_helper.rb +0 -2
- data/rails_example/app/mailers/.keep +0 -0
- data/rails_example/app/models/.keep +0 -0
- data/rails_example/app/models/application_record.rb +0 -3
- data/rails_example/app/models/concerns/.keep +0 -0
- data/rails_example/app/models/guest.rb +0 -18
- data/rails_example/app/models/post.rb +0 -2
- data/rails_example/app/views/layouts/application.html.erb +0 -15
- data/rails_example/app/workers/simple_worker.rb +0 -15
- data/rails_example/app/workers/slow_until_executing_worker.rb +0 -15
- data/rails_example/app/workers/spawn_simple_worker.rb +0 -10
- data/rails_example/app/workers/while_executing_worker.rb +0 -12
- data/rails_example/app/workers/without_args_worker.rb +0 -16
- data/rails_example/app/workers/without_argument_worker.rb +0 -12
- data/rails_example/bin/bundle +0 -3
- data/rails_example/bin/check_or_setup_db +0 -56
- data/rails_example/bin/docker-setup +0 -20
- data/rails_example/bin/rails +0 -4
- data/rails_example/bin/rake +0 -4
- data/rails_example/bin/setup +0 -34
- data/rails_example/bin/update +0 -29
- data/rails_example/cable.ru +0 -6
- data/rails_example/common-services.yml +0 -52
- data/rails_example/config/application.rb +0 -27
- data/rails_example/config/boot.rb +0 -3
- data/rails_example/config/cable.yml +0 -9
- data/rails_example/config/database.docker.yml +0 -12
- data/rails_example/config/database.yml +0 -19
- data/rails_example/config/environment.rb +0 -5
- data/rails_example/config/environments/development.rb +0 -54
- data/rails_example/config/environments/production.rb +0 -86
- data/rails_example/config/environments/test.rb +0 -42
- data/rails_example/config/initializers/application_controller_renderer.rb +0 -6
- data/rails_example/config/initializers/assets.rb +0 -11
- data/rails_example/config/initializers/backtrace_silencers.rb +0 -9
- data/rails_example/config/initializers/cookies_serializer.rb +0 -5
- data/rails_example/config/initializers/filter_parameter_logging.rb +0 -4
- data/rails_example/config/initializers/inflections.rb +0 -16
- data/rails_example/config/initializers/mime_types.rb +0 -4
- data/rails_example/config/initializers/new_framework_defaults.rb +0 -23
- data/rails_example/config/initializers/session_store.rb +0 -3
- data/rails_example/config/initializers/sidekiq.rb +0 -13
- data/rails_example/config/initializers/wrap_parameters.rb +0 -14
- data/rails_example/config/locales/en.yml +0 -23
- data/rails_example/config/puma.rb +0 -38
- data/rails_example/config/routes.rb +0 -8
- data/rails_example/config/secrets.yml +0 -22
- data/rails_example/config/sidekiq.yml +0 -6
- data/rails_example/config/spring.rb +0 -6
- data/rails_example/config.ru +0 -4
- data/rails_example/db/migrate/20160724111322_create_posts.rb +0 -12
- data/rails_example/db/schema.rb +0 -25
- data/rails_example/db/seeds.rb +0 -7
- data/rails_example/dev-entrypoint.sh +0 -55
- data/rails_example/dev.env +0 -12
- data/rails_example/docker/rails.Dockerfile +0 -27
- data/rails_example/docker-compose.yml +0 -71
- data/rails_example/lib/assets/.keep +0 -0
- data/rails_example/lib/tasks/.keep +0 -0
- data/rails_example/log/.keep +0 -0
- data/rails_example/public/404.html +0 -67
- data/rails_example/public/422.html +0 -67
- data/rails_example/public/500.html +0 -66
- data/rails_example/public/favicon.ico +0 -0
- data/rails_example/public/robots.txt +0 -5
- data/rails_example/simple.ru +0 -12
- data/rails_example/spec/controllers/work_controller_mock_spec.rb +0 -91
- data/rails_example/spec/controllers/work_controller_spec.rb +0 -77
- data/rails_example/spec/factories/posts.rb +0 -8
- data/rails_example/spec/models/post_spec.rb +0 -4
- data/rails_example/spec/rails_helper.rb +0 -20
- data/rails_example/spec/spec_helper.rb +0 -20
- data/rails_example/spec/support/sidekiq_meta.rb +0 -12
- data/rails_example/spec/workers/simple_worker_spec.rb +0 -4
- data/rails_example/vendor/assets/javascripts/.keep +0 -0
- data/rails_example/vendor/assets/stylesheets/.keep +0 -0
- data/spec/jobs/another_unique_job.rb +0 -13
- data/spec/jobs/custom_queue_job.rb +0 -5
- data/spec/jobs/custom_queue_job_with_filter_method.rb +0 -7
- data/spec/jobs/custom_queue_job_with_filter_proc.rb +0 -10
- data/spec/jobs/expiring_job.rb +0 -4
- data/spec/jobs/inline_worker.rb +0 -8
- data/spec/jobs/just_a_worker.rb +0 -7
- data/spec/jobs/long_running_job.rb +0 -6
- data/spec/jobs/main_job.rb +0 -7
- data/spec/jobs/my_job.rb +0 -12
- data/spec/jobs/my_unique_job.rb +0 -11
- data/spec/jobs/my_unique_job_with_filter_method.rb +0 -17
- data/spec/jobs/my_unique_job_with_filter_proc.rb +0 -15
- data/spec/jobs/notify_worker.rb +0 -10
- data/spec/jobs/plain_class.rb +0 -3
- data/spec/jobs/simple_worker.rb +0 -11
- data/spec/jobs/spawn_simple_worker.rb +0 -8
- data/spec/jobs/test_class.rb +0 -3
- data/spec/jobs/unique_job_with_conditional_parameter.rb +0 -14
- data/spec/jobs/unique_job_with_filter_method.rb +0 -18
- data/spec/jobs/unique_job_with_nil_unique_args.rb +0 -16
- data/spec/jobs/unique_job_with_no_unique_args_method.rb +0 -12
- data/spec/jobs/unique_job_withthout_unique_args_parameter.rb +0 -14
- data/spec/jobs/unique_on_all_queues_job.rb +0 -13
- data/spec/jobs/until_and_while_executing_job.rb +0 -7
- data/spec/jobs/until_executed_job.rb +0 -17
- data/spec/jobs/until_executing_job.rb +0 -7
- data/spec/jobs/until_global_timeout_job.rb +0 -8
- data/spec/jobs/until_timeout_job.rb +0 -8
- data/spec/jobs/while_executing_job.rb +0 -12
- data/spec/jobs/without_argument_job.rb +0 -9
- data/spec/lib/sidekiq_unique_jobs/cli_spec.rb +0 -183
- data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +0 -316
- data/spec/lib/sidekiq_unique_jobs/config_spec.rb +0 -84
- data/spec/lib/sidekiq_unique_jobs/core_ext_spec.rb +0 -25
- data/spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb +0 -42
- data/spec/lib/sidekiq_unique_jobs/lock/until_executed_spec.rb +0 -37
- data/spec/lib/sidekiq_unique_jobs/lock/until_timeout_spec.rb +0 -26
- data/spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb +0 -86
- data/spec/lib/sidekiq_unique_jobs/normalizer_spec.rb +0 -21
- data/spec/lib/sidekiq_unique_jobs/options_with_fallback_spec.rb +0 -113
- data/spec/lib/sidekiq_unique_jobs/queue_lock_timeout_calculator_spec.rb +0 -47
- data/spec/lib/sidekiq_unique_jobs/run_lock_timeout_calculator_spec.rb +0 -36
- data/spec/lib/sidekiq_unique_jobs/script_mock_spec.rb +0 -88
- data/spec/lib/sidekiq_unique_jobs/scripts/acquire_lock_spec.rb +0 -50
- data/spec/lib/sidekiq_unique_jobs/scripts/release_lock_spec.rb +0 -41
- data/spec/lib/sidekiq_unique_jobs/scripts_spec.rb +0 -68
- data/spec/lib/sidekiq_unique_jobs/server/middleware_spec.rb +0 -78
- data/spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb +0 -164
- data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb +0 -75
- data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_jobs_spec.rb +0 -41
- data/spec/lib/sidekiq_unique_jobs/timeout_calculator_spec.rb +0 -70
- data/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb +0 -257
- data/spec/lib/sidekiq_unique_jobs/unlockable_spec.rb +0 -37
- data/spec/lib/sidekiq_unique_jobs/util_spec.rb +0 -81
- data/spec/spec_helper.rb +0 -92
- data/spec/support/matchers/redis_matchers.rb +0 -29
- data/spec/support/ruby_meta.rb +0 -17
- data/spec/support/sidekiq_meta.rb +0 -30
- data/spec/support/unique_macros.rb +0 -71
@@ -1,257 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::UniqueArgs do
|
4
|
-
let(:item) { { 'class' => 'UntilExecutedJob', 'queue' => 'myqueue', 'args' => [[1, 2]] } }
|
5
|
-
subject { described_class.new(item) }
|
6
|
-
describe '#unique_digest' do
|
7
|
-
context 'when args are empty' do
|
8
|
-
let(:item) { { 'class' => 'WithoutArgumentJob', 'args' => [] } }
|
9
|
-
let(:another_subject) { described_class.new(item) }
|
10
|
-
|
11
|
-
context 'with the same unique args' do
|
12
|
-
it 'equals to unique_digest for that item' do
|
13
|
-
expect(subject.unique_digest).to eq(another_subject.unique_digest)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
shared_examples 'unique digest' do
|
19
|
-
subject { described_class.new(item_options) }
|
20
|
-
context 'given another item' do
|
21
|
-
let(:another_subject) { described_class.new(another_item) }
|
22
|
-
|
23
|
-
context 'with the same unique args' do
|
24
|
-
let(:another_item) { item_options.merge('args' => [1, 2, 'type' => 'it']) }
|
25
|
-
it 'equals to unique_digest for that item' do
|
26
|
-
expect(subject.unique_digest).to eq(another_subject.unique_digest)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'with different unique args' do
|
31
|
-
let(:another_item) { item_options.merge('args' => [1, 3, 'type' => 'that']) }
|
32
|
-
it 'differs from unique_digest for that item' do
|
33
|
-
expect(subject.unique_digest).not_to eq(another_subject.unique_digest)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when unique_args is a proc' do
|
40
|
-
let(:item_options) do
|
41
|
-
{
|
42
|
-
'class' => 'MyUniqueJobWithFilterProc',
|
43
|
-
'queue' => 'customqueue',
|
44
|
-
'args' => [1, 2, 'type' => 'it'],
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
it_behaves_like 'unique digest'
|
49
|
-
end
|
50
|
-
|
51
|
-
context 'when unique_args is a symbol' do
|
52
|
-
let(:item_options) do
|
53
|
-
{
|
54
|
-
'class' => 'MyUniqueJobWithFilterMethod',
|
55
|
-
'queue' => 'customqueue',
|
56
|
-
'args' => [1, 2, 'type' => 'it'],
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
it_behaves_like 'unique digest'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '#unique_args_enabled?' do
|
65
|
-
with_default_worker_options(unique: :until_executed, unique_args: ->(args) { args[1]['test'] }) do
|
66
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args) do
|
67
|
-
its(:unique_args_enabled?) { is_expected.to eq(:unique_args) }
|
68
|
-
end
|
69
|
-
|
70
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: false) do
|
71
|
-
its(:unique_args_enabled?) { is_expected.to be_a(Proc) }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
with_default_worker_options(unique: false, unique_args: nil) do
|
76
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args) do
|
77
|
-
its(:unique_args_enabled?) { is_expected.to eq(:unique_args) }
|
78
|
-
end
|
79
|
-
|
80
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: false) do
|
81
|
-
its(:unique_args_enabled?) { is_expected.to be_falsy }
|
82
|
-
end
|
83
|
-
|
84
|
-
its(:unique_args_enabled?) { is_expected.to be_falsy }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#unique_on_all_queues?' do
|
89
|
-
with_global_config(unique_args_enabled: true) do
|
90
|
-
its(:unique_on_all_queues?) { is_expected.to eq(nil) }
|
91
|
-
|
92
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: true) do
|
93
|
-
its(:unique_on_all_queues?) { is_expected.to eq(true) }
|
94
|
-
end
|
95
|
-
|
96
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: false) do
|
97
|
-
its(:unique_on_all_queues?) { is_expected.to be_falsy }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
with_global_config(unique_args_enabled: false) do
|
102
|
-
its(:unique_on_all_queues?) { is_expected.to eq(nil) }
|
103
|
-
|
104
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: false) do
|
105
|
-
its(:unique_on_all_queues?) { is_expected.to eq(false) }
|
106
|
-
end
|
107
|
-
|
108
|
-
with_sidekiq_options_for(UntilExecutedJob, unique_args: :unique_args, unique_on_all_queues: true) do
|
109
|
-
its(:unique_on_all_queues?) { is_expected.to eq(true) }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe '#filter_by_proc' do
|
115
|
-
let(:filter) { ->(args) { args[1]['test'] } }
|
116
|
-
let(:args) { [1, 'test' => 'it'] }
|
117
|
-
let(:unique_args) { described_class.new(item) }
|
118
|
-
|
119
|
-
subject { unique_args.filter_by_proc(args) }
|
120
|
-
|
121
|
-
context 'without any default worker options configured' do
|
122
|
-
before do
|
123
|
-
allow(unique_args).to receive(:unique_args_method).and_return(filter)
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'returns the value of theoptions hash ' do
|
127
|
-
expect(subject).to eq('it')
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'when #unique_args_method is nil' do
|
132
|
-
before do
|
133
|
-
allow(unique_args).to receive(:unique_args_method).and_return(nil)
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'returns the value of theoptions hash ' do
|
137
|
-
expect(SidekiqUniqueJobs.logger).to receive(:warn) do |&block|
|
138
|
-
expect(block.call).to eq('filter_by_proc : unique_args_method is nil. Returning ([1, {"test"=>"it"}])')
|
139
|
-
end
|
140
|
-
expect(subject).to eq(args)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
with_default_worker_options(unique: :until_executed, unique_args: ->(args) { args[1]['test'] }) do
|
145
|
-
it 'returns the value of the provided options' do
|
146
|
-
expect(subject).to eq('it')
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe '#filter_by_symbol' do
|
152
|
-
let(:unique_args) { described_class.new(item) }
|
153
|
-
|
154
|
-
context 'when filter is a working symbol' do
|
155
|
-
let(:item) do
|
156
|
-
{ 'class' => 'UniqueJobWithFilterMethod',
|
157
|
-
'queue' => 'myqueue',
|
158
|
-
'args' => [[1, 2]] }
|
159
|
-
end
|
160
|
-
|
161
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
162
|
-
subject { unique_args.filter_by_symbol(args) }
|
163
|
-
|
164
|
-
it 'returns the value of the provided class method' do
|
165
|
-
expected = %w[name test]
|
166
|
-
expect(unique_args.logger).to receive(:debug) do |&block|
|
167
|
-
expect(block.call).to eq("filter_by_symbol : filtered_args(#{args}) => #{expected}")
|
168
|
-
end
|
169
|
-
expect(subject).to eq(expected)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'when worker takes conditional parameters' do
|
174
|
-
let(:item) do
|
175
|
-
{ 'class' => 'UniqueJobWithoutUniqueArgsParameter',
|
176
|
-
'queue' => 'myqueue',
|
177
|
-
'args' => [1] }
|
178
|
-
end
|
179
|
-
let(:args) { [1] }
|
180
|
-
|
181
|
-
subject { unique_args.filter_by_symbol(args) }
|
182
|
-
|
183
|
-
it 'returns the value of the provided class method' do
|
184
|
-
expect(subject).to eq(args)
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when provided nil' do
|
188
|
-
let(:args) { [] }
|
189
|
-
it 'returns the value of the provided class method' do
|
190
|
-
expect(subject).to eq(args)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context "when workers unique_args method doesn't take parameters" do
|
196
|
-
let(:item) do
|
197
|
-
{ 'class' => 'UniqueJobWithoutUniqueArgsParameter',
|
198
|
-
'queue' => 'myqueue',
|
199
|
-
'args' => [[1, 2]] }
|
200
|
-
end
|
201
|
-
|
202
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
203
|
-
subject { unique_args.filter_by_symbol(args) }
|
204
|
-
|
205
|
-
it 'returns the value of the provided class method' do
|
206
|
-
expect(unique_args.logger)
|
207
|
-
.to receive(:fatal)
|
208
|
-
.with('filter_by_symbol : UniqueJobWithoutUniqueArgsParameter\'s unique_args needs at least one argument')
|
209
|
-
expect(unique_args.logger).to receive(:fatal).with a_kind_of(ArgumentError)
|
210
|
-
|
211
|
-
expect(subject).to eq(args)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context 'when @worker_class does not respond_to unique_args_method' do
|
216
|
-
let(:item) do
|
217
|
-
{ 'class' => 'UniqueJobWithNoUniqueArgsMethod',
|
218
|
-
'queue' => 'myqueue',
|
219
|
-
'args' => [[1, 2]] }
|
220
|
-
end
|
221
|
-
|
222
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
223
|
-
subject { unique_args.filter_by_symbol(args) }
|
224
|
-
|
225
|
-
it 'returns the value of the provided class method' do
|
226
|
-
expect(unique_args.logger).to receive(:warn) do |&block|
|
227
|
-
expect(block.call)
|
228
|
-
.to eq(
|
229
|
-
"filter_by_symbol : UniqueJobWithNoUniqueArgsMethod does not respond to filtered_args). " \
|
230
|
-
"Returning (#{args})",
|
231
|
-
)
|
232
|
-
end
|
233
|
-
|
234
|
-
expect(subject).to eq(args)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context 'when workers unique_args method returns nil' do
|
239
|
-
let(:item) do
|
240
|
-
{ 'class' => 'UniqueJobWithNilUniqueArgs',
|
241
|
-
'queue' => 'myqueue',
|
242
|
-
'args' => [[1, 2]] }
|
243
|
-
end
|
244
|
-
|
245
|
-
let(:args) { ['name', 2, 'whatever' => nil, 'type' => 'test'] }
|
246
|
-
subject { unique_args.filter_by_symbol(args) }
|
247
|
-
|
248
|
-
it 'returns the value of the provided class method' do
|
249
|
-
expect(unique_args.logger).to receive(:debug) do |&block|
|
250
|
-
expect(block.call).to eq("filter_by_symbol : unique_args(#{args}) => ")
|
251
|
-
end
|
252
|
-
|
253
|
-
expect(subject).to eq(nil)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Unlockable do
|
4
|
-
def item_with_digest
|
5
|
-
SidekiqUniqueJobs::UniqueArgs.digest(item)
|
6
|
-
item
|
7
|
-
end
|
8
|
-
let(:item) do
|
9
|
-
{ 'class' => MyUniqueJob,
|
10
|
-
'queue' => 'customqueue',
|
11
|
-
'args' => [1, 2] }
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:unique_digest) { item_with_digest[SidekiqUniqueJobs::UNIQUE_DIGEST_KEY] }
|
15
|
-
describe '.unlock_by_key' do
|
16
|
-
before do
|
17
|
-
end
|
18
|
-
|
19
|
-
specify do
|
20
|
-
expect(SidekiqUniqueJobs::Util.keys.count).to eq(0)
|
21
|
-
jid = Sidekiq::Client.push(item_with_digest)
|
22
|
-
|
23
|
-
expect(SidekiqUniqueJobs::Util.keys.count).to eq(1)
|
24
|
-
expect(SidekiqUniqueJobs::Util.keys).to match_array([unique_digest])
|
25
|
-
expect(SidekiqUniqueJobs::Util.unique_key(jid)).to eq(unique_digest)
|
26
|
-
|
27
|
-
described_class.unlock_by_key(
|
28
|
-
unique_digest,
|
29
|
-
jid,
|
30
|
-
)
|
31
|
-
|
32
|
-
expect(SidekiqUniqueJobs::Util.keys.count).to eq(0)
|
33
|
-
expect(SidekiqUniqueJobs::Util.keys).not_to match_array([unique_digest])
|
34
|
-
expect(SidekiqUniqueJobs::Util.unique_key(jid)).to eq(nil)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Util do
|
4
|
-
let(:job) do
|
5
|
-
{
|
6
|
-
'class' => 'MyUniqueJob',
|
7
|
-
'args' => [[1, 2]],
|
8
|
-
'at' => 1_492_341_850.358196,
|
9
|
-
'retry' => true,
|
10
|
-
'queue' => 'customqueue',
|
11
|
-
'unique' => :until_executed,
|
12
|
-
'unique_expiration' => 7200,
|
13
|
-
'retry_count' => 10,
|
14
|
-
'jid' => jid,
|
15
|
-
'created_at' => 1_492_341_790.358217,
|
16
|
-
}
|
17
|
-
end
|
18
|
-
let(:unique_args) { SidekiqUniqueJobs::UniqueArgs.new(job) }
|
19
|
-
let(:unique_key) { unique_args.unique_digest }
|
20
|
-
let(:jid) { 'e3049b05b0bd9c809182bbe0' }
|
21
|
-
|
22
|
-
def acquire_lock
|
23
|
-
SidekiqUniqueJobs::Scripts::AcquireLock.execute(nil, unique_key, jid, 1)
|
24
|
-
end
|
25
|
-
|
26
|
-
describe '.keys' do
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '.del' do
|
30
|
-
before do
|
31
|
-
acquire_lock
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'deletes the keys by pattern' do
|
35
|
-
expect(described_class.del(described_class::SCAN_PATTERN, 100, false)).to eq(1)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'deletes the keys by distinct key' do
|
39
|
-
expect(described_class.del(unique_key, 100, false)).to eq(1)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '.expire' do
|
44
|
-
before do
|
45
|
-
acquire_lock
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'does some shit' do
|
49
|
-
sleep 1
|
50
|
-
expected = { jid => unique_key }
|
51
|
-
expect(described_class.unique_hash).to match(expected)
|
52
|
-
removed_keys = described_class.expire
|
53
|
-
expect(removed_keys).to match(expected)
|
54
|
-
expect(described_class.unique_hash).not_to match(expected)
|
55
|
-
expect(described_class.keys('*')).not_to include(unique_key)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '.prefix' do
|
60
|
-
before do
|
61
|
-
allow(SidekiqUniqueJobs.config).to receive(:unique_prefix).and_return('test-uniqueness')
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'returns a prefixed key' do
|
65
|
-
expect(described_class.prefix('key')).to eq('test-uniqueness:key')
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'when .unique_prefix is nil?' do
|
69
|
-
it 'does not prefix with unique_prefix' do
|
70
|
-
allow(SidekiqUniqueJobs.config).to receive(:unique_prefix).and_return(nil)
|
71
|
-
expect(described_class.prefix('key')).to eq('key')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'when key is already prefixed' do
|
76
|
-
it 'does not add another prefix' do
|
77
|
-
expect(described_class.prefix('test-uniqueness:key')).to eq('test-uniqueness:key')
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
VERSION_REGEX = /(?<operator>[<>=]+)?\s?(?<version>(\d+.?)+)/m
|
2
|
-
if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.4.0'
|
3
|
-
require 'simplecov'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'pry-byebug'
|
7
|
-
rescue LoadError
|
8
|
-
puts 'Pry unavailable'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
require 'rspec'
|
13
|
-
require 'rspec/its'
|
14
|
-
|
15
|
-
require 'sidekiq'
|
16
|
-
require 'sidekiq/util'
|
17
|
-
require 'sidekiq-unique-jobs'
|
18
|
-
require 'timecop'
|
19
|
-
require 'sidekiq_unique_jobs/testing'
|
20
|
-
require 'sidekiq/simulator'
|
21
|
-
|
22
|
-
Sidekiq::Testing.disable!
|
23
|
-
SidekiqUniqueJobs.logger.level = "Logger::#{ENV.fetch('LOGLEVEL') { 'error' }.upcase}".constantize
|
24
|
-
|
25
|
-
require 'sidekiq/redis_connection'
|
26
|
-
|
27
|
-
REDIS_URL ||= ENV['REDIS_URL'] || 'redis://localhost/15'.freeze
|
28
|
-
REDIS_NAMESPACE ||= 'unique-test'.freeze
|
29
|
-
REDIS_OPTIONS ||= { url: REDIS_URL } # rubocop:disable MutableConstant
|
30
|
-
REDIS_OPTIONS[:namespace] = REDIS_NAMESPACE if defined?(Redis::Namespace)
|
31
|
-
REDIS ||= Sidekiq::RedisConnection.create(REDIS_OPTIONS)
|
32
|
-
|
33
|
-
Sidekiq.configure_client do |config|
|
34
|
-
config.redis = REDIS_OPTIONS
|
35
|
-
end
|
36
|
-
|
37
|
-
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
|
38
|
-
|
39
|
-
RSpec.configure do |config| # rubocop:disable BlockLength
|
40
|
-
config.expect_with :rspec do |expectations|
|
41
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
42
|
-
end
|
43
|
-
config.mock_with :rspec do |mocks|
|
44
|
-
mocks.verify_partial_doubles = true
|
45
|
-
end
|
46
|
-
config.filter_run :focus unless ENV['CI']
|
47
|
-
config.run_all_when_everything_filtered = true
|
48
|
-
config.disable_monkey_patching!
|
49
|
-
config.warnings = false
|
50
|
-
config.default_formatter = 'doc' if config.files_to_run.one?
|
51
|
-
config.order = :random
|
52
|
-
Kernel.srand config.seed
|
53
|
-
|
54
|
-
config.before(:each) do
|
55
|
-
SidekiqUniqueJobs.configure do |unique_config|
|
56
|
-
unique_config.redis_test_mode = :redis
|
57
|
-
end
|
58
|
-
Sidekiq.redis = REDIS
|
59
|
-
Sidekiq.redis(&:flushdb)
|
60
|
-
Sidekiq::Worker.clear_all
|
61
|
-
Sidekiq::Queues.clear_all
|
62
|
-
|
63
|
-
if Sidekiq::Testing.respond_to?(:server_middleware)
|
64
|
-
Sidekiq::Testing.server_middleware do |chain|
|
65
|
-
chain.add SidekiqUniqueJobs::Server::Middleware
|
66
|
-
end
|
67
|
-
end
|
68
|
-
enable_delay = defined?(Sidekiq::Extensions) && Sidekiq::Extensions.respond_to?(:enable_delay!)
|
69
|
-
Sidekiq::Extensions.enable_delay! if enable_delay
|
70
|
-
end
|
71
|
-
|
72
|
-
config.after(:each) do
|
73
|
-
Sidekiq.redis(&:flushdb)
|
74
|
-
respond_to_middleware = defined?(Sidekiq::Testing) && Sidekiq::Testing.respond_to?(:server_middleware)
|
75
|
-
Sidekiq::Testing.server_middleware(&:clear) if respond_to_middleware
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
Dir[File.join(File.dirname(__FILE__), 'jobs', '**', '*.rb')].each { |f| require f }
|
80
|
-
|
81
|
-
def capture(stream)
|
82
|
-
begin
|
83
|
-
stream = stream.to_s
|
84
|
-
eval "$#{stream} = StringIO.new" # rubocop:disable Security/Eval
|
85
|
-
yield
|
86
|
-
result = eval("$#{stream}").string # rubocop:disable Security/Eval
|
87
|
-
ensure
|
88
|
-
eval("$#{stream} = #{stream.upcase}") # rubocop:disable Security/Eval
|
89
|
-
end
|
90
|
-
|
91
|
-
result
|
92
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'rspec/expectations'
|
2
|
-
|
3
|
-
RSpec::Matchers.define :have_key do |unique_key|
|
4
|
-
Sidekiq.redis do |redis|
|
5
|
-
match do |_unique_jobs|
|
6
|
-
@value = redis.get(unique_key)
|
7
|
-
@ttl = redis.ttl(unique_key)
|
8
|
-
|
9
|
-
@value && with_value && for_seconds
|
10
|
-
end
|
11
|
-
|
12
|
-
chain :with_value do |value = nil|
|
13
|
-
@expected_value = value
|
14
|
-
@expected_value && @value == @expected_value
|
15
|
-
end
|
16
|
-
|
17
|
-
chain :for_seconds do |ttl = nil|
|
18
|
-
@expected_ttl = ttl
|
19
|
-
@expected_ttl && @ttl == @expected_ttl
|
20
|
-
end
|
21
|
-
|
22
|
-
failure_message do |_actual|
|
23
|
-
msg = "expected Redis to have key #{unique_key}"
|
24
|
-
msg << " with value #{@expected_value} was (#{@value})" if @expected_value
|
25
|
-
msg << " with value #{@expected_ttl} was (#{@ttl})" if @expected_ttl
|
26
|
-
msg
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/spec/support/ruby_meta.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.before(:each) do |example|
|
3
|
-
ruby_ver = example.metadata[:ruby_ver]
|
4
|
-
VERSION_REGEX.match(ruby_ver.to_s) do |match|
|
5
|
-
version = match[:version]
|
6
|
-
operator = match[:operator]
|
7
|
-
next unless ruby_ver
|
8
|
-
|
9
|
-
raise 'Please specify how to compare the version with >= or < or =' unless operator
|
10
|
-
|
11
|
-
unless RUBY_VERSION.send(operator, version)
|
12
|
-
skip("Skipped due to version check (requirement was that ruby version is " \
|
13
|
-
"#{operator} #{version}; was #{RUBY_VERSION})")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.before(:each) do |example|
|
3
|
-
SidekiqUniqueJobs.configure do |c|
|
4
|
-
c.redis_test_mode = :redis
|
5
|
-
end
|
6
|
-
|
7
|
-
if (sidekiq = example.metadata[:sidekiq])
|
8
|
-
sidekiq = :fake if sidekiq == true
|
9
|
-
Sidekiq::Testing.send("#{sidekiq}!")
|
10
|
-
end
|
11
|
-
|
12
|
-
if (sidekiq_ver = example.metadata[:sidekiq_ver])
|
13
|
-
VERSION_REGEX.match(sidekiq_ver.to_s) do |match|
|
14
|
-
version = match[:version]
|
15
|
-
operator = match[:operator]
|
16
|
-
|
17
|
-
raise 'Please specify how to compare the version with >= or < or =' unless operator
|
18
|
-
|
19
|
-
unless Sidekiq::VERSION.send(operator, version)
|
20
|
-
skip("Skipped due to version check (requirement was that sidekiq version is " \
|
21
|
-
"#{operator} #{version}; was #{Sidekiq::VERSION})")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
config.after(:each) do |example|
|
28
|
-
Sidekiq::Testing.disable! unless example.metadata[:sidekiq].nil?
|
29
|
-
end
|
30
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module SidekiqUniqueJobs
|
2
|
-
module RSpec
|
3
|
-
module InstanceMethods
|
4
|
-
# enable versioning for specific blocks (at instance-level)
|
5
|
-
def with_global_config(config)
|
6
|
-
was_config = SidekiqUniqueJobs.config
|
7
|
-
SidekiqUniqueJobs.configure(config)
|
8
|
-
yield
|
9
|
-
ensure
|
10
|
-
SidekiqUniqueJobs.configure(was_config)
|
11
|
-
end
|
12
|
-
|
13
|
-
def with_sidekiq_options_for(worker_class, options)
|
14
|
-
worker_class = SidekiqUniqueJobs.worker_class_constantize(worker_class)
|
15
|
-
if worker_class.respond_to?(:sidekiq_options)
|
16
|
-
was_options = worker_class.get_sidekiq_options
|
17
|
-
worker_class.sidekiq_options(options)
|
18
|
-
end
|
19
|
-
yield
|
20
|
-
ensure
|
21
|
-
worker_class.sidekiq_options_hash = was_options if worker_class.respond_to?(:sidekiq_options_hash=)
|
22
|
-
end
|
23
|
-
|
24
|
-
def with_default_worker_options(options)
|
25
|
-
was_options = Sidekiq.default_worker_options
|
26
|
-
Sidekiq.default_worker_options.clear
|
27
|
-
Sidekiq.default_worker_options = options
|
28
|
-
yield
|
29
|
-
ensure
|
30
|
-
Sidekiq.default_worker_options.clear
|
31
|
-
Sidekiq.default_worker_options = was_options
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module ClassMethods
|
36
|
-
def with_sidekiq_options_for(worker_class, options = {}, &block)
|
37
|
-
context "with sidekiq options #{options}" do
|
38
|
-
around(:each) do |ex|
|
39
|
-
with_sidekiq_options_for(worker_class, options, &ex)
|
40
|
-
end
|
41
|
-
class_exec(&block)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# enable versioning for specific blocks (at class-level)
|
46
|
-
def with_global_config(config = {}, &block)
|
47
|
-
context "with global configuration #{config}" do
|
48
|
-
around(:each) do |ex|
|
49
|
-
with_global_config(config, &ex)
|
50
|
-
end
|
51
|
-
class_exec(&block)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# enable versioning for specific blocks (at class-level)
|
56
|
-
def with_default_worker_options(config = {}, &block)
|
57
|
-
context "with default sidekiq options #{config}" do
|
58
|
-
around(:each) do |ex|
|
59
|
-
with_default_worker_options(config, &ex)
|
60
|
-
end
|
61
|
-
class_exec(&block)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
RSpec.configure do |config|
|
69
|
-
config.include SidekiqUniqueJobs::RSpec::InstanceMethods
|
70
|
-
config.extend SidekiqUniqueJobs::RSpec::ClassMethods
|
71
|
-
end
|