Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
russointroitoa committed Apr 21, 2024
1 parent 62f26a4 commit 3bbe116
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
11 changes: 7 additions & 4 deletions lib/sidekiq/grouping/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,20 @@ def ns(key = nil)
"batching:#{key}"
end

def server_version
Sidekiq.redis do |conn|
conn.info["redis_version"]
end
end

#
# The optimized LUA SCRIPT works from Redis greater than or equal to 6.2.
# Check Redis version in use and return the suitable PLUCK_SCRIPT
#
# @return [<Type>] <description>
#
def pluck_script
redis_version = Sidekiq.redis do |conn|
conn.info(:server)["redis_version"]
end
if Gem::Version.new(redis_version) >= Gem::Version.new("6.2.0")
if server_version >= "6.2.0"
PLUCK_SCRIPT_GTE_6_2_0
else
PLUCK_SCRIPT_LT_6_2_0
Expand Down
20 changes: 7 additions & 13 deletions spec/modules/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,19 @@
end

describe "#pluck_script" do
context "when Redis version is" do
context "when Redis server version is" do
it ">= 6.2.0, selects the corresponding pluck script" do
allow_any_instance_of(RedisClient).to receive(:call)
.with(:info, anything)
.and_return(
{ "redis_version" => "6.2.0" }
)
expect(redis_service.pluck_script).to eq(
allow_any_instance_of(described_class).to receive(:server_version)
.and_return("6.2.0")
expect(redis_service.send(:pluck_script)).to eq(
described_class::PLUCK_SCRIPT_GTE_6_2_0
)
end

it "< 6.2.0, selects the corresponding pluck script" do
allow_any_instance_of(RedisClient).to receive(:call)
.with(:info, anything)
.and_return(
{ "redis_version" => "6.0.0" }
)
expect(redis_service.pluck_script).to eq(
allow_any_instance_of(described_class).to receive(:server_version)
.and_return("6.0.0")
expect(redis_service.send(:pluck_script)).to eq(
described_class::PLUCK_SCRIPT_LT_6_2_0
)
end
Expand Down

0 comments on commit 3bbe116

Please sign in to comment.