Skip to content

Commit

Permalink
fix: Sidekiq 7.2 throws TypeError: Unsupported command argument type:…
Browse files Browse the repository at this point in the history
… TrueClass when using byscore: true (mhenrixon#815)

fix: Sidekiq 7.2 TypeError: invalid type TrueClass
  • Loading branch information
Amnesthesia authored and semenyukdmitry committed Jan 8, 2024
1 parent 9e4e293 commit 0d25c3c
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 62 deletions.
4 changes: 2 additions & 2 deletions lib/sidekiq_unique_jobs/orphans/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def enabled?
# @return [void]
#
def register_reaper_process
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, nx: true, ex: drift_reaper_interval) }
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "nx", "ex", drift_reaper_interval) }
end

#
Expand All @@ -202,7 +202,7 @@ def register_reaper_process
# @return [void]
#
def refresh_reaper_mutex
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, ex: drift_reaper_interval) }
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "ex", drift_reaper_interval) }
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def call
def expired_digests
max_score = (start_time - reaper_timeout).to_f

conn.zrange(EXPIRING_DIGESTS, 0, max_score, byscore: true)
conn.zrange(EXPIRING_DIGESTS, 0, max_score, "byscore")
end

#
Expand Down
7 changes: 4 additions & 3 deletions lib/sidekiq_unique_jobs/redis/sorted_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class SortedSet < Entity
# @return [Hash] when given with_scores: true
#
def entries(with_scores: true)
entrys = redis { |conn| conn.zrange(key, 0, -1, withscores: with_scores) }
return entrys unless with_scores
return redis { |conn| conn.zrange(key, 0, -1) } unless with_scores

entrys.each_with_object({}) { |pair, hash| hash[pair[0]] = pair[1] }
redis { |conn| conn.zrange(key, 0, -1, "withscores") }.each_with_object({}) do |pair, hash|
hash[pair[0]] = pair[1]
end
end

#
Expand Down
4 changes: 3 additions & 1 deletion spec/performance/lock_digest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::LockDigest, perf: true do
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath
RSpec.describe SidekiqUniqueJobs::LockDigest, :perf do
let(:lock_digest) { described_class.new(item) }
let(:job_class) { UntilExecutedJob }
let(:class_name) { worker_class.to_s }
Expand Down Expand Up @@ -50,3 +51,4 @@
end
end
end
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath
4 changes: 3 additions & 1 deletion spec/performance/locksmith_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

RSpec.describe SidekiqUniqueJobs::Locksmith, perf: true do
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath
RSpec.describe SidekiqUniqueJobs::Locksmith, :perf do
let(:locksmith_one) { described_class.new(item_one) }
let(:locksmith_two) { described_class.new(item_two) }

Expand Down Expand Up @@ -49,3 +50,4 @@
expect { locksmith_one.lock {} }.to perform_allocation(Array => 12_640, Hash => 13_888).bytes
end
end
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath
28 changes: 14 additions & 14 deletions spec/sidekiq_unique_jobs/changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

it "adds a new entry" do
expect { add }.to change { entity.entries.size }.by(1)
expect(add).to be == 1
expect(add).to eq 1
end
end

Expand All @@ -39,14 +39,14 @@

it "clears out all entries" do
expect { clear }.to change { entity.entries.size }.by(-1)
expect(clear).to be == 1
expect(clear).to eq 1
end
end

context "without entries" do
it "returns 0 (zero)" do
expect { clear }.not_to change { entity.entries.size }
expect(clear).to be == 0
expect(clear).to eq 0
end
end
end
Expand All @@ -55,27 +55,27 @@
subject(:exist?) { entity.exist? }

context "when no entries exist" do
it { is_expected.to be == false }
it { is_expected.to be false }
end

context "when entries exist" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == true }
it { is_expected.to be true }
end
end

describe "#pttl" do
subject(:pttl) { entity.pttl }

context "when no entries exist" do
it { is_expected.to be == -2 }
it { is_expected.to eq(-2) }
end

context "when entries exist without expiration" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == -1 }
it { is_expected.to eq(-1) }
end

context "when entries exist with expiration" do
Expand All @@ -92,13 +92,13 @@
subject(:ttl) { entity.ttl }

context "when no entries exist" do
it { is_expected.to be == -2 }
it { is_expected.to eq(-2) }
end

context "when entries exist without expiration" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == -1 }
it { is_expected.to eq(-1) }
end

context "when entries exist with expiration" do
Expand All @@ -107,15 +107,15 @@
expire(key.changelog, 600)
end

it { is_expected.to be == 600 }
it { is_expected.to eq 600 }
end
end

describe "#expires?" do
subject(:expires?) { entity.expires? }

context "when no entries exist" do
it { is_expected.to be == false }
it { is_expected.to be false }
end

context "when entries exist" do
Expand All @@ -124,21 +124,21 @@
expire(key.changelog, 600)
end

it { is_expected.to be == true }
it { is_expected.to be true }
end
end

describe "#count" do
subject(:count) { entity.count }

context "when no entries exist" do
it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end

context "when entries exist" do
before { simulate_lock(key, job_id) }

it { is_expected.to be == 2 }
it { is_expected.to eq 2 }
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/sidekiq_unique_jobs/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
jobs del PATTERN
Options:
d, [--dry-run], [--no-dry-run] # set to false to perform deletion
c, [--count=N] # The max number of digests to return
# Default: 1000
-d, [--dry-run], [--no-dry-run] # set to false to perform deletion
-c, [--count=N] # The max number of digests to return
# Default: 1000
deletes unique digests from redis by pattern
HEADER
Expand All @@ -55,8 +55,8 @@
jobs list PATTERN
Options:
c, [--count=N] # The max number of digests to return
# Default: 1000
-c, [--count=N] # The max number of digests to return
# Default: 1000
list all unique digests and their expiry time
HEADER
Expand Down
4 changes: 2 additions & 2 deletions spec/sidekiq_unique_jobs/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# rubocop:disable RSpec/FilePath
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath
RSpec.describe SidekiqUniqueJobs do
describe "define custom lock strategies" do
subject(:middleware_call) do
Expand Down Expand Up @@ -65,4 +65,4 @@ def lock
end
end
end
# rubocop:enable RSpec/FilePath
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath
12 changes: 6 additions & 6 deletions spec/sidekiq_unique_jobs/lua/delete_by_digest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
it "deletes the expected keys from redis" do
expect(delete_by_digest).to eq(8)

expect(queued.count).to be == 0
expect(primed.count).to be == 0
expect(locked.count).to be == 0
expect(queued.count).to eq 0
expect(primed.count).to eq 0
expect(locked.count).to eq 0

expect(run_queued.count).to be == 0
expect(run_primed.count).to be == 0
expect(run_locked.count).to be == 0
expect(run_queued.count).to eq 0
expect(run_primed.count).to eq 0
expect(run_locked.count).to eq 0
end
end
2 changes: 1 addition & 1 deletion spec/sidekiq_unique_jobs/lua/lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let(:now_f) { SidekiqUniqueJobs.now_f }
let(:lock_limit) { 1 }

shared_context "with a primed key", with_primed_key: true do
shared_context "with a primed key", :with_primed_key do
before do
call_script(:queue, key.to_a, argv_one)
rpoplpush(key.queued, key.primed)
Expand Down
12 changes: 6 additions & 6 deletions spec/sidekiq_unique_jobs/lua/unlock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
let(:locked_jid) { job_id_one }
let(:lock_limit) { 1 }

shared_context "with a lock", with_a_lock: true do
shared_context "with a lock", :with_a_lock do
before do
call_script(:queue, key.to_a, argv_one)
rpoplpush(key.queued, key.primed)
Expand Down Expand Up @@ -172,10 +172,10 @@
it "does not unlock" do
expect { unlock }.to change { changelogs.count }.by(1)

expect(queued.count).to be == 0
expect(primed.count).to be == 0
expect(queued.count).to eq 0
expect(primed.count).to eq 0

expect(locked.count).to be == 1
expect(locked.count).to eq 1
expect(locked.entries).to contain_exactly(job_id_two)
expect(locked[job_id_two].to_f).to be_within(0.5).of(now_f)
end
Expand All @@ -189,9 +189,9 @@
expect(queued.count).to eq(1)
expect(queued.entries).to contain_exactly("1")

expect(primed.count).to be == 0
expect(primed.count).to eq 0

expect(locked.count).to be == 0
expect(locked.count).to eq 0
expect(locked.entries).to eq([])
expect(locked[job_id_one]).to be_nil
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# rubocop:disable RSpec/FilePath, RSpec/DescribeMethod
# rubocop:disable RSpec/SpecFilePathFormat, RSpec/FilePath, RSpec/DescribeMethod
RSpec.describe SidekiqUniqueJobs::Middleware::Server, "lock: :until_and_while_executing" do
let(:server) { described_class.new }

Expand Down Expand Up @@ -46,4 +46,4 @@
end
end
end
# rubocop:enable RSpec/FilePath, RSpec/DescribeMethod
# rubocop:enable RSpec/SpecFilePathFormat, RSpec/FilePath, RSpec/DescribeMethod
4 changes: 2 additions & 2 deletions spec/sidekiq_unique_jobs/redis/hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
subject(:count) { entity.count }

context "without entries" do
it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end

context "with entries" do
before { hset(digest, job_id, now_f) }

it { is_expected.to be == 1 }
it { is_expected.to eq 1 }
end
end
end
4 changes: 2 additions & 2 deletions spec/sidekiq_unique_jobs/redis/set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
subject(:count) { entity.count }

context "without entries" do
it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end

context "with entries" do
before { sadd(digest, job_id) }

it { is_expected.to be == 1 }
it { is_expected.to eq 1 }
end
end
end
14 changes: 7 additions & 7 deletions spec/sidekiq_unique_jobs/redis/sorted_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,35 @@
context "when given an array of arrays" do
let(:values) { [[1.0, "string"], [2.0, "other"]] }

it { is_expected.to be == 2 }
it { is_expected.to eq 2 }
end

context "when given a string entries" do
let(:values) { "abcdef" }

it { is_expected.to be == 1 }
it { is_expected.to eq 1 }
end
end

describe "#count" do
subject(:count) { entity.count }

context "without entries" do
it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end

context "with entries" do
before { zadd(digest, now_f, job_id) }

it { is_expected.to be == 1 }
it { is_expected.to eq 1 }
end
end

describe "#clear" do
subject(:clear) { entity.clear }

context "without entries" do
it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end

context "with entries" do
Expand All @@ -77,7 +77,7 @@
zcard(digest)
end

it { is_expected.to be == 100 }
it { is_expected.to eq 100 }
end
end

Expand Down Expand Up @@ -105,7 +105,7 @@
context "with entries" do
before { zadd(digest, now_f, job_id) }

it { is_expected.to be == 0 }
it { is_expected.to eq 0 }
end
end
end
Loading

0 comments on commit 0d25c3c

Please sign in to comment.