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,84 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Config do
|
4
|
-
let(:args) do
|
5
|
-
{
|
6
|
-
|
7
|
-
unique_prefix: 'unique',
|
8
|
-
default_queue_lock_expiration: 30 * 60,
|
9
|
-
default_run_lock_expiration: 60,
|
10
|
-
default_lock: :while_executing,
|
11
|
-
redis_test_mode: :redis,
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
subject do
|
16
|
-
described_class.new(args)
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#testing_enabled?' do
|
20
|
-
context 'when Sidekiq::Testing is undefined' do
|
21
|
-
before { hide_const('Sidekiq::Testing') }
|
22
|
-
its(:testing_enabled?) do
|
23
|
-
is_expected.to eq(false)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when Sidekiq::Testing is defined' do
|
28
|
-
context 'and Sidekiq::Testing.enabled? is false' do
|
29
|
-
before { allow(Sidekiq::Testing).to receive(:enabled?).and_return(false) }
|
30
|
-
its(:testing_enabled?) do
|
31
|
-
is_expected.to eq(false)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'and Sidekiq::Testing.enabled? is true' do
|
36
|
-
before { allow(Sidekiq::Testing).to receive(:enabled?).and_return(true) }
|
37
|
-
its(:testing_enabled?) do
|
38
|
-
is_expected.to eq(true)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#inline_testing_enabled?' do
|
45
|
-
context 'when testing_enabled? is false' do
|
46
|
-
before { allow(subject).to receive(:testing_enabled?).and_return(false) }
|
47
|
-
its(:inline_testing_enabled?) do
|
48
|
-
is_expected.to eq(false)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
context 'when testing_enabled? is true' do
|
52
|
-
before { allow(subject).to receive(:testing_enabled?).and_return(true) }
|
53
|
-
|
54
|
-
context 'and Sidekiq::Testing.inline? is false' do
|
55
|
-
before { allow(Sidekiq::Testing).to receive(:inline?).and_return(false) }
|
56
|
-
its(:inline_testing_enabled?) do
|
57
|
-
is_expected.to eq(false)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'and Sidekiq::Testing.inline? is true' do
|
62
|
-
before { allow(Sidekiq::Testing).to receive(:inline?).and_return(true) }
|
63
|
-
its(:inline_testing_enabled?) do
|
64
|
-
is_expected.to eq(true)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '#mocking?' do
|
71
|
-
context 'when redis_test_mode is :redis' do
|
72
|
-
its(:mocking?) do
|
73
|
-
is_expected.to eq(false)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when redis_test_mode is :mock' do
|
78
|
-
subject { described_class.new(args.merge(redis_test_mode: :mock)) }
|
79
|
-
its(:mocking?) do
|
80
|
-
is_expected.to eq(true)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Hash do
|
4
|
-
subject { { test: :me, not: :me } }
|
5
|
-
|
6
|
-
describe '#slice' do
|
7
|
-
specify { expect(subject.slice(:test)).to eq(test: :me) }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#slice!' do
|
11
|
-
specify { expect { subject.slice!(:test) }.to change { subject }.to(test: :me) }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
RSpec.describe String do
|
16
|
-
describe '#classify' do
|
17
|
-
subject { 'under_scored_string' }
|
18
|
-
its(:classify) { is_expected.to eq('UnderScoredString') }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#camelize' do
|
22
|
-
subject { 'under_scored_string' }
|
23
|
-
its(:camelize) { is_expected.to eq('UnderScoredString') }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Lock::UntilAndWhileExecuting do
|
4
|
-
let(:item) do
|
5
|
-
{
|
6
|
-
'jid' => 'maaaahjid',
|
7
|
-
'queue' => 'dupsallowed',
|
8
|
-
'class' => 'UntilAndWhileExecuting',
|
9
|
-
'unique' => 'until_executed',
|
10
|
-
'args' => [1],
|
11
|
-
}
|
12
|
-
end
|
13
|
-
let(:callback) { -> {} }
|
14
|
-
subject { described_class.new(item) }
|
15
|
-
|
16
|
-
describe '#execute' do
|
17
|
-
before do
|
18
|
-
subject.lock(:client)
|
19
|
-
end
|
20
|
-
let(:runtime_lock) { SidekiqUniqueJobs::Lock::WhileExecuting.new(item, nil) }
|
21
|
-
|
22
|
-
it 'unlocks the unique key before yielding' do
|
23
|
-
expect(SidekiqUniqueJobs::Lock::WhileExecuting)
|
24
|
-
.to receive(:new).with(item, nil)
|
25
|
-
.and_return(runtime_lock)
|
26
|
-
|
27
|
-
expect(callback).to receive(:call)
|
28
|
-
|
29
|
-
subject.execute(callback) do
|
30
|
-
Sidekiq.redis do |c|
|
31
|
-
expect(c.keys('uniquejobs:*').size).to eq(1)
|
32
|
-
end
|
33
|
-
|
34
|
-
10.times { Sidekiq::Client.push(item) }
|
35
|
-
|
36
|
-
Sidekiq.redis do |c|
|
37
|
-
expect(c.keys('uniquejobs:*').size).to eq(2)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Lock::UntilExecuted do
|
4
|
-
describe '#execute' do
|
5
|
-
subject { described_class.new(item) }
|
6
|
-
let(:item) do
|
7
|
-
{ 'jid' => 'maaaahjid', 'class' => 'UntilExecutedJob', 'unique' => 'until_executed' }
|
8
|
-
end
|
9
|
-
let(:empty_callback) { -> {} }
|
10
|
-
|
11
|
-
def execute
|
12
|
-
subject.execute(empty_callback)
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when yield fails with Sidekiq::Shutdown' do
|
16
|
-
before do
|
17
|
-
allow(subject).to receive(:after_yield_yield) { raise Sidekiq::Shutdown }
|
18
|
-
allow(subject).to receive(:unlock).and_return(true)
|
19
|
-
expect(subject).not_to receive(:unlock)
|
20
|
-
expect(subject.logger).to receive(:fatal)
|
21
|
-
expect(empty_callback).not_to receive(:call)
|
22
|
-
end
|
23
|
-
|
24
|
-
specify { expect { subject.execute(empty_callback) }.to raise_error(Sidekiq::Shutdown) }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when yield fails with other errors' do
|
28
|
-
before do
|
29
|
-
allow(subject).to receive(:after_yield_yield) { raise 'Hell' }
|
30
|
-
expect(subject).to receive(:unlock).and_return(true)
|
31
|
-
expect(empty_callback).to receive(:call)
|
32
|
-
end
|
33
|
-
|
34
|
-
specify { expect { subject.execute(empty_callback) }.to raise_error('Hell') }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Lock::UntilTimeout do
|
4
|
-
subject { described_class.new(item) }
|
5
|
-
let(:item) do
|
6
|
-
{ 'jid' => 'maaaahjid',
|
7
|
-
'class' => 'UntilExecutedJob',
|
8
|
-
'unique' => 'until_timeout' }
|
9
|
-
end
|
10
|
-
let(:empty_callback) { -> {} }
|
11
|
-
|
12
|
-
describe '#unlock' do
|
13
|
-
context 'when provided :server' do
|
14
|
-
it 'returns true' do
|
15
|
-
expect(subject.unlock(:server)).to eq(true)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'when provided with anything else than :server' do
|
20
|
-
it 'raises a helpful error message' do
|
21
|
-
expect { subject.unlock(:client) }
|
22
|
-
.to raise_error(ArgumentError, /client middleware can't unlock uniquejobs:*/)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Lock::WhileExecuting do
|
4
|
-
let(:item) do
|
5
|
-
{
|
6
|
-
'jid' => 'maaaahjid',
|
7
|
-
'queue' => 'dupsallowed',
|
8
|
-
'class' => 'UntilAndWhileExecuting',
|
9
|
-
'unique' => 'until_executed',
|
10
|
-
'unique_digest' => 'test_mutex_key',
|
11
|
-
'args' => [1],
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'allows only one mutex object to have the lock at a time' do
|
16
|
-
mutexes = (1..10).map do
|
17
|
-
described_class.new(item)
|
18
|
-
end
|
19
|
-
|
20
|
-
x = 0
|
21
|
-
mutexes.map do |m|
|
22
|
-
Thread.new do
|
23
|
-
m.synchronize do
|
24
|
-
y = x
|
25
|
-
sleep 0.1
|
26
|
-
x = y + 1
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end.map(&:join)
|
30
|
-
|
31
|
-
expect(x).to eq(10)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'expires the lock on the mutex object after run_lock_expiration if specified' do
|
35
|
-
mutexes = (1..10).map do
|
36
|
-
described_class.new(item)
|
37
|
-
end
|
38
|
-
|
39
|
-
worker = SidekiqUniqueJobs.worker_class_constantize(item[SidekiqUniqueJobs::CLASS_KEY])
|
40
|
-
allow(worker).to receive(:get_sidekiq_options)
|
41
|
-
.and_return('retry' => true,
|
42
|
-
'queue' => :dupsallowed,
|
43
|
-
'run_lock_expiration' => 0,
|
44
|
-
'unique' => :until_and_while_executing)
|
45
|
-
|
46
|
-
start_times = []
|
47
|
-
sleep_time = 0.1
|
48
|
-
mutexes.each_with_index.map do |m, i|
|
49
|
-
Thread.new do
|
50
|
-
m.synchronize do
|
51
|
-
start_times[i] = Time.now
|
52
|
-
sleep sleep_time
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end.map(&:join)
|
56
|
-
|
57
|
-
expect(start_times.size).to be 10
|
58
|
-
expect(start_times.sort.last - start_times.sort.first).to be < sleep_time * 10
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'handles auto cleanup correctly' do
|
62
|
-
m = described_class.new(item)
|
63
|
-
|
64
|
-
SidekiqUniqueJobs.connection do |conn|
|
65
|
-
conn.set 'test_mutex_key:run', Time.now.to_i - 1, nx: true
|
66
|
-
end
|
67
|
-
|
68
|
-
start = Time.now.to_i
|
69
|
-
m.synchronize do
|
70
|
-
'nop'
|
71
|
-
end
|
72
|
-
|
73
|
-
# no longer than a second
|
74
|
-
expect(Time.now.to_i).to be <= start + 1
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'maintains mutex semantics' do
|
78
|
-
m = described_class.new(item)
|
79
|
-
|
80
|
-
expect do
|
81
|
-
m.synchronize do
|
82
|
-
m.synchronize {}
|
83
|
-
end
|
84
|
-
end.to raise_error(ThreadError)
|
85
|
-
end
|
86
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Normalizer do
|
4
|
-
def jsonify(args)
|
5
|
-
described_class.jsonify(args)
|
6
|
-
end
|
7
|
-
|
8
|
-
describe '.jsonify' do
|
9
|
-
specify do
|
10
|
-
original = [1, :test, [test: :test]]
|
11
|
-
expected = [1, 'test', ['test' => 'test']]
|
12
|
-
expect(jsonify(original)).to eq(expected)
|
13
|
-
end
|
14
|
-
|
15
|
-
specify do
|
16
|
-
original = [1, :test, [test: [test: :test]]]
|
17
|
-
expected = [1, 'test', ['test' => ['test' => 'test']]]
|
18
|
-
expect(jsonify(original)).to eq(expected)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::OptionsWithFallback do
|
4
|
-
include described_class
|
5
|
-
subject { self }
|
6
|
-
|
7
|
-
describe '#unique_lock' do
|
8
|
-
context 'when options have `unique: true`' do
|
9
|
-
let(:options) { { 'unique' => true } }
|
10
|
-
|
11
|
-
it 'warns when unique is set to true' do
|
12
|
-
expect(subject)
|
13
|
-
.to receive(:warn)
|
14
|
-
.with(
|
15
|
-
'unique: true is no longer valid. Please set it to the type of lock required like: ' \
|
16
|
-
'`unique: :until_executed`',
|
17
|
-
)
|
18
|
-
|
19
|
-
subject.unique_lock
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when options have `unique: :while_executing`' do
|
24
|
-
let(:options) { { 'unique' => 'while_executing' } }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#unique_enabled?' do
|
29
|
-
let(:options) { {} }
|
30
|
-
let(:item) { {} }
|
31
|
-
its(:unique_enabled?) { is_expected.to eq(nil) }
|
32
|
-
|
33
|
-
context 'when options["unique"] is present' do
|
34
|
-
let(:options) { { 'unique' => 'while_executing' } }
|
35
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
36
|
-
its(:unique_enabled?) { is_expected.to eq('while_executing') }
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when item["unique"] is present' do
|
40
|
-
let(:options) { {} }
|
41
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
42
|
-
its(:unique_enabled?) { is_expected.to eq('until_executed') }
|
43
|
-
|
44
|
-
context 'when true' do
|
45
|
-
let(:options) { {} }
|
46
|
-
let(:item) { { 'unique' => true } }
|
47
|
-
its(:unique_enabled?) { is_expected.to eq(true) }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#unique_disabled?' do
|
53
|
-
let(:options) { {} }
|
54
|
-
let(:item) { {} }
|
55
|
-
its(:unique_disabled?) { is_expected.to be_truthy }
|
56
|
-
|
57
|
-
context 'when options["unique"] is present' do
|
58
|
-
let(:options) { { 'unique' => 'while_executing' } }
|
59
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
60
|
-
its(:unique_disabled?) { is_expected.to be_falsey }
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'when item["unique"] is present' do
|
64
|
-
let(:options) { {} }
|
65
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
66
|
-
its(:unique_disabled?) { is_expected.to be_falsey }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe '#lock_type' do
|
71
|
-
context 'when options["unique"] is while_executing' do
|
72
|
-
let(:options) { { 'unique' => 'while_executing' } }
|
73
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
74
|
-
its(:lock_type) { is_expected.to eq('while_executing') }
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'when options["unique"] is true' do
|
78
|
-
let(:options) { { 'unique' => true } }
|
79
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
80
|
-
its(:lock_type) { is_expected.to eq('until_executed') }
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'when item["unique"] is until_executed' do
|
84
|
-
let(:options) { {} }
|
85
|
-
let(:item) { { 'unique' => 'until_executed' } }
|
86
|
-
its(:lock_type) { is_expected.to eq('until_executed') }
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when item["unique"] is true' do
|
90
|
-
let(:options) { { 'unique' => true } }
|
91
|
-
let(:item) { { 'unique' => true } }
|
92
|
-
its(:lock_type) { is_expected.to eq(nil) }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '#options' do
|
97
|
-
context 'when worker_class respond_to get_sidekiq_options' do
|
98
|
-
let(:worker_class) { SimpleWorker }
|
99
|
-
its(:options) { is_expected.to eq(SimpleWorker.get_sidekiq_options) }
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'when default_worker_options has been configured' do
|
103
|
-
let(:worker_class) { PlainClass }
|
104
|
-
before do
|
105
|
-
allow(Sidekiq)
|
106
|
-
.to receive(:default_worker_options)
|
107
|
-
.and_return('unique' => 'while_executing')
|
108
|
-
end
|
109
|
-
|
110
|
-
its(:options) { is_expected.to eq(Sidekiq.default_worker_options) }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::QueueLockTimeoutCalculator do
|
4
|
-
shared_context 'generic unscheduled job' do
|
5
|
-
subject { described_class.new('class' => 'JustAWorker') }
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'public api' do
|
9
|
-
it_behaves_like 'generic unscheduled job' do
|
10
|
-
it { is_expected.to respond_to(:seconds) }
|
11
|
-
it { is_expected.to respond_to(:queue_lock_expiration) }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '.for_item' do
|
16
|
-
it 'initializes a new calculator' do
|
17
|
-
expect(described_class).to receive(:new).with('WAT')
|
18
|
-
described_class.for_item('WAT')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#seconds' do
|
23
|
-
subject { described_class.new(nil) }
|
24
|
-
|
25
|
-
before do
|
26
|
-
allow(subject).to receive(:time_until_scheduled).and_return(10)
|
27
|
-
allow(subject).to receive(:queue_lock_expiration).and_return(9)
|
28
|
-
end
|
29
|
-
its(:seconds) { is_expected.to eq(19) }
|
30
|
-
end
|
31
|
-
|
32
|
-
describe '#queue_lock_expiration' do
|
33
|
-
context 'using default unique_expiration' do
|
34
|
-
subject { described_class.new(nil) }
|
35
|
-
before { allow(subject).to receive(:worker_class_queue_lock_expiration).and_return(nil) }
|
36
|
-
|
37
|
-
its(:queue_lock_expiration) { is_expected.to eq(1_800) }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'using specified sidekiq option unique_expiration' do
|
41
|
-
subject { described_class.new(nil) }
|
42
|
-
before { allow(subject).to receive(:worker_class_queue_lock_expiration).and_return(9) }
|
43
|
-
|
44
|
-
its(:queue_lock_expiration) { is_expected.to eq(9) }
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::RunLockTimeoutCalculator do
|
4
|
-
shared_context 'generic unscheduled job' do
|
5
|
-
subject { described_class.new('class' => 'JustAWorker') }
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'public api' do
|
9
|
-
it_behaves_like 'generic unscheduled job' do
|
10
|
-
it { is_expected.to respond_to(:seconds) }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '.for_item' do
|
15
|
-
it 'initializes a new calculator' do
|
16
|
-
expect(described_class).to receive(:new).with('WAT')
|
17
|
-
described_class.for_item('WAT')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#seconds' do
|
22
|
-
context 'using default run_lock_expiration' do
|
23
|
-
subject { described_class.new(nil) }
|
24
|
-
before { allow(subject).to receive(:worker_class_run_lock_expiration).and_return(9) }
|
25
|
-
|
26
|
-
its(:seconds) { is_expected.to eq(9) }
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'using specified sidekiq option run_lock_expiration' do
|
30
|
-
subject { described_class.new(nil) }
|
31
|
-
before { allow(subject).to receive(:worker_class_run_lock_expiration).and_return(nil) }
|
32
|
-
|
33
|
-
its(:seconds) { is_expected.to eq(60) }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'mock_redis'
|
5
|
-
MOCK_REDIS ||= MockRedis.new
|
6
|
-
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
7
|
-
# This is a known issue (we only run this spec for ruby 2.4.1)
|
8
|
-
end
|
9
|
-
|
10
|
-
RSpec.describe SidekiqUniqueJobs::ScriptMock, ruby_ver: '>= 2.4.1' do
|
11
|
-
MD5_DIGEST ||= 'unique'.freeze
|
12
|
-
UNIQUE_KEY ||= 'uniquejobs:unique'.freeze
|
13
|
-
JID ||= 'fuckit'.freeze
|
14
|
-
ANOTHER_JID ||= 'anotherjid'.freeze
|
15
|
-
|
16
|
-
before do
|
17
|
-
SidekiqUniqueJobs.configure do |config|
|
18
|
-
config.redis_test_mode = :mock
|
19
|
-
end
|
20
|
-
Sidekiq::Worker.clear_all
|
21
|
-
|
22
|
-
keys = MOCK_REDIS.keys
|
23
|
-
if keys.respond_to?(:each)
|
24
|
-
keys.each do |key|
|
25
|
-
MOCK_REDIS.del(key)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
MOCK_REDIS.del(keys)
|
29
|
-
end
|
30
|
-
|
31
|
-
allow(Sidekiq).to receive(:redis).and_yield(MOCK_REDIS)
|
32
|
-
end
|
33
|
-
|
34
|
-
after do
|
35
|
-
SidekiqUniqueJobs.configure do |config|
|
36
|
-
config.redis_test_mode = :redis
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
subject { SidekiqUniqueJobs::Scripts }
|
41
|
-
|
42
|
-
def lock_for(seconds = 1, jid = JID, key = UNIQUE_KEY)
|
43
|
-
subject.call(:acquire_lock, nil, keys: [key], argv: [jid, seconds])
|
44
|
-
end
|
45
|
-
|
46
|
-
def unlock(key = UNIQUE_KEY, jid = JID)
|
47
|
-
subject.call(:release_lock, nil, keys: [key], argv: [jid])
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '.acquire_lock' do
|
51
|
-
context 'when job is unique' do
|
52
|
-
specify { expect(lock_for).to eq(1) }
|
53
|
-
specify do
|
54
|
-
expect(lock_for(1)).to eq(1)
|
55
|
-
expect(SidekiqUniqueJobs)
|
56
|
-
.to have_key(UNIQUE_KEY)
|
57
|
-
.for_seconds(1)
|
58
|
-
.with_value('fuckit')
|
59
|
-
sleep 1
|
60
|
-
expect(lock_for).to eq(1)
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'when job is locked' do
|
64
|
-
before { expect(lock_for(10)).to eq(1) }
|
65
|
-
specify { expect(lock_for(5, ANOTHER_JID)).to eq(0) }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '.release_lock' do
|
70
|
-
context 'when job is locked by another jid' do
|
71
|
-
before { expect(lock_for(10, ANOTHER_JID)).to eq(1) }
|
72
|
-
specify { expect(unlock).to eq(0) }
|
73
|
-
after { unlock(UNIQUE_KEY, ANOTHER_JID) }
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when job is not locked at all' do
|
77
|
-
specify { expect(unlock).to eq(-1) }
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when job is locked by the same jid' do
|
81
|
-
specify do
|
82
|
-
expect(lock_for(10)).to eq(1)
|
83
|
-
expect(unlock).to eq(1)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe SidekiqUniqueJobs::Scripts::AcquireLock do
|
4
|
-
let(:redis_pool) { nil }
|
5
|
-
let(:jid) { 'abcdefab' }
|
6
|
-
let(:unique_key) { 'uniquejobs:123asdasd2134' }
|
7
|
-
let(:max_lock_time) { 1 }
|
8
|
-
|
9
|
-
describe '.execute' do
|
10
|
-
subject { instance_double(described_class) }
|
11
|
-
|
12
|
-
it 'delegates to instance' do
|
13
|
-
expect(described_class).to receive(:new)
|
14
|
-
.with(redis_pool, unique_key, jid, max_lock_time)
|
15
|
-
.and_return(subject)
|
16
|
-
expect(subject).to receive(:execute).and_return(true)
|
17
|
-
|
18
|
-
described_class.execute(redis_pool, unique_key, jid, max_lock_time)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe '#execute' do
|
23
|
-
context 'when job is unique' do
|
24
|
-
def execute(myjid = jid, key = unique_key, max_lock = max_lock_time)
|
25
|
-
described_class.execute(
|
26
|
-
redis_pool,
|
27
|
-
key,
|
28
|
-
myjid,
|
29
|
-
max_lock,
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
specify { expect(execute(jid, unique_key, max_lock_time)).to eq(true) }
|
34
|
-
specify do
|
35
|
-
expect(execute(jid, unique_key, max_lock_time)).to eq(true)
|
36
|
-
expect(SidekiqUniqueJobs)
|
37
|
-
.to have_key(unique_key)
|
38
|
-
.for_seconds(max_lock_time)
|
39
|
-
.with_value('abcdefab')
|
40
|
-
sleep 0.5
|
41
|
-
expect(execute).to eq(true)
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'when a unique_key exists for another jid' do
|
45
|
-
before { expect(execute(jid, unique_key, 10)).to eq(true) }
|
46
|
-
specify { expect(execute('anotherjid', unique_key, 5)).to eq(false) }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|