Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access to hash members #496

Merged
merged 3 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/lock_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ def errors_as_string

# the strategy to use as conflict resolution from sidekiq client
def on_client_conflict
@on_client_conflict ||= on_conflict&.(:[], :client) if on_conflict.is_a?(Hash)
@on_client_conflict ||= on_conflict[:client] if on_conflict.is_a?(Hash)
@on_client_conflict ||= on_conflict
end

# the strategy to use as conflict resolution from sidekiq server
def on_server_conflict
@on_client_conflict ||= on_conflict&.(:[], :server) if on_conflict.is_a?(Hash)
@on_server_conflict ||= on_conflict[:server] if on_conflict.is_a?(Hash)
@on_server_conflict ||= on_conflict
end
end
Expand Down
24 changes: 0 additions & 24 deletions lib/sidekiq_unique_jobs/lua/find_digest_in_sorted_set.lua

This file was deleted.

24 changes: 0 additions & 24 deletions lib/sidekiq_unique_jobs/lua/shared/find_digest_in_sorted_set.lua

This file was deleted.

96 changes: 96 additions & 0 deletions spec/sidekiq_unique_jobs/lock_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::LockConfig do
subject { lock_config }

let(:lock_config) { described_class.from_worker(item) }

let(:item) do
{
lock: lock_type,
class: worker_class,
lock_limit: lock_limit,
lock_timeout: lock_timeout,
lock_ttl: lock_ttl,
lock_info: lock_info,
on_conflict: on_conflict,
errors: errors,
}
end

let(:lock_type) { :until_executed }
let(:worker_class) { "UntilExecutedJob" }
let(:lock_limit) { 2 }
let(:lock_timeout) { 5 }
let(:lock_ttl) { 2000 }
let(:lock_info) { true }
let(:on_conflict) { :log }
let(:errors) { {} }

its(:type) { is_expected.to eq(lock_type) }
its(:worker) { is_expected.to eq(worker_class) }
its(:limit) { is_expected.to eq(lock_limit) }
its(:timeout) { is_expected.to eq(lock_timeout) }
its(:ttl) { is_expected.to eq(lock_ttl) }
its(:lock_info) { is_expected.to eq(lock_info) }
its(:on_conflict) { is_expected.to eq(on_conflict) }
its(:errors) { is_expected.to eq({}) }

describe "#wait_for_lock?" do
subject(:wait_for_lock?) { lock_config.wait_for_lock? }

context "when timeout is nil" do
let(:lock_timeout) { nil }

it { is_expected.to eq(true) }
end

context "when timeout is positive?" do
let(:lock_timeout) { 3 }

it { is_expected.to eq(true) }
end

context "when timeout is zero?" do
let(:lock_timeout) { 0 }

it { is_expected.to eq(false) }
end
end

describe "#valid?" do
subject(:valid?) { lock_config.valid? }

it { is_expected.to eq(true) }

context "when errors are present" do
let(:errors) { { any: :thing } }

it { is_expected.to eq(false) }
end
end

describe "#on_client_conflict" do
subject(:on_client_conflict) { lock_config.on_client_conflict }

it { is_expected.to eq(:log) }

context "when on_conflict is a hash" do
let(:on_conflict) { { client: :replace, server: :reschedule } }

it { is_expected.to eq(:replace) }
end
end

describe "#on_server_conflict" do
subject(:on_server_conflict) { lock_config.on_server_conflict }

it { is_expected.to eq(:log) }

context "when on_conflict is a hash" do
let(:on_conflict) { { client: :replace, server: :reschedule } }

it { is_expected.to eq(:reschedule) }
end
end
end