-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow old until_timeout jobs to keep working * Unlock and delete legacy keys * Invert the logic a little Allow the NEW lock to be created if the old job would have been the one that created the lock. * Fix the old acquire_lock (OMG!!) so broken... * Add coverage for automatic lock migration * Rubo👮
- Loading branch information
Showing
8 changed files
with
165 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
spec/integration/sidekiq_unique_jobs/legacy_lock_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
# rubocop:disable RSpec/FilePath | ||
RSpec.describe SidekiqUniqueJobs::Locksmith, redis: :redis do | ||
let(:locksmith_one) { described_class.new(lock_item) } | ||
let(:lock_expiration) { nil } | ||
let(:redis_pool) { nil } | ||
let(:jid_one) { 'maaaahjid' } | ||
let(:jid_two) { 'anotherjid' } | ||
let(:unique_digest) { 'uniquejobs:test_mutex_key' } | ||
let(:queue) { 'dupsallowed' } | ||
let(:unique) { :until_executed } | ||
let(:worker_class) { UntilExecutedJob } | ||
let(:lock_item) do | ||
{ | ||
'args' => [1], | ||
'class' => UntilExecutedJob, | ||
'jid' => jid_one, | ||
'lock_expiration' => lock_expiration, | ||
'queue' => queue, | ||
'unique' => unique, | ||
'unique_digest' => unique_digest, | ||
} | ||
end | ||
|
||
let(:locksmith_two) { described_class.new(lock_item_two) } | ||
let(:lock_item_two) { lock_item.merge('jid' => jid_two) } | ||
|
||
context 'with a legacy lock' do | ||
before do | ||
result = SidekiqUniqueJobs::Scripts.call( | ||
:acquire_lock, | ||
redis_pool, | ||
keys: [unique_digest], | ||
argv: [lock_value, lock_expiration], | ||
) | ||
|
||
expect(result).to eq(1) | ||
expect(unique_keys).to include(unique_digest) | ||
end | ||
|
||
context 'when lock_expiration is unset' do | ||
let(:lock_value) { jid_one } | ||
|
||
it 'can signal to expire the lock after 10' do | ||
locksmith_one.signal(jid_one) | ||
|
||
expect(ttl(unique_digest)).to eq(-1) # key exists but has been expired | ||
end | ||
|
||
it 'can soft delete the lock' do | ||
expect(locksmith_one.delete).to eq(nil) | ||
expect(unique_keys).not_to include(unique_digest) | ||
end | ||
|
||
it 'can force delete the lock' do | ||
expect(locksmith_one.delete!).to eq(nil) | ||
expect(unique_keys).not_to include(unique_digest) | ||
end | ||
end | ||
|
||
context 'when lock_expiration is set' do | ||
let(:lock_value) { jid_one } | ||
let(:lock_expiration) { 10 } | ||
|
||
it 'can signal to expire the lock after 10' do | ||
locksmith_one.signal(jid_one) | ||
|
||
expect(ttl(unique_digest)).to be_within(1).of(10) | ||
end | ||
|
||
it 'cannot soft delete the lock' do | ||
expect(locksmith_one.delete).to eq(nil) | ||
expect(unique_keys).to include(unique_digest) | ||
end | ||
|
||
it 'can force delete the lock' do | ||
expect(locksmith_one.delete!).to eq(nil) | ||
expect(unique_keys).not_to include(unique_digest) | ||
end | ||
end | ||
|
||
context 'when the value of unique_digest is 2' do | ||
let(:lock_value) { '2' } | ||
|
||
it 'returns the stored jid' do | ||
expect(locksmith_one.lock(0)).to eq(jid_one) | ||
end | ||
end | ||
|
||
context 'when the value of unique_digest is jid' do | ||
let(:lock_value) { jid_one } | ||
|
||
it 'returns the stored jid' do | ||
expect(locksmith_one.lock(0)).to eq(jid_one) | ||
end | ||
|
||
it 'can not be locked by another jid' do | ||
expect(locksmith_two.lock(0)).to eq(nil) | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable RSpec/FilePath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters