Skip to content

Commit

Permalink
Mock RedisClient instead of Hashie
Browse files Browse the repository at this point in the history
  • Loading branch information
russointroitoa committed Aug 14, 2023
1 parent 972215c commit 62f26a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/sidekiq/grouping/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def ns(key = nil)
# @return [<Type>] <description>
#
def pluck_script
redis_version = Sidekiq.redis { |conn| conn.info["redis_version"] }
redis_version = Sidekiq.redis do |conn|
conn.info(:server)["redis_version"]
end
if Gem::Version.new(redis_version) >= Gem::Version.new("6.2.0")
PLUCK_SCRIPT_GTE_6_2_0
else
Expand Down
1 change: 0 additions & 1 deletion sidekiq-grouping.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rubocop-rspec"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "timecop"
spec.add_development_dependency "hashie"

spec.add_dependency "activesupport"
spec.add_dependency "concurrent-ruby"
Expand Down
22 changes: 10 additions & 12 deletions spec/modules/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,22 @@
describe "#pluck_script" do
context "when Redis version is" do
it ">= 6.2.0, selects the corresponding pluck script" do
mock_redis_client = Hashie::Mash.new(
info: { "redis_version" => "6.2.0" }
)
allow_any_instance_of(described_class).to receive(:redis).and_yield(
mock_redis_client
)
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(
described_class::PLUCK_SCRIPT_GTE_6_2_0
)
end

it "< 6.2.0, selects the corresponding pluck script" do
mock_redis_client = Hashie::Mash.new(
info: { "redis_version" => "6.0.0" }
)
allow_any_instance_of(described_class).to receive(:redis).and_yield(
mock_redis_client
)
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(
described_class::PLUCK_SCRIPT_LT_6_2_0
)
Expand Down

0 comments on commit 62f26a4

Please sign in to comment.