spec/modules/redis_spec.rb in sidekiq-grouping-1.2.0 vs spec/modules/redis_spec.rb in sidekiq-grouping-1.3.0
- old
+ new
@@ -1,48 +1,44 @@
# frozen_string_literal: true
require "spec_helper"
describe Sidekiq::Grouping::Redis do
+ include Sidekiq::Grouping::RedisDispatcher
+
subject(:redis_service) { described_class.new }
let(:queue_name) { "my_queue" }
let(:key) { "batching:#{queue_name}" }
let(:unique_key) { "batching:#{queue_name}:unique_messages" }
describe "#push_msg" do
it "adds message to queue", :aggregate_failures do
redis_service.push_msg(queue_name, "My message")
- expect(redis { |c| c.llen key }).to eq 1
- expect(redis { |c| c.lrange key, 0, 1 }).to eq ["My message"]
- expect(redis { |c| c.smembers unique_key }).to eq []
+ expect(redis_call(:llen, key)).to eq 1
+ expect(redis_call(:lrange, key, 0, 1)).to eq ["My message"]
+ expect(redis_call(:smembers, unique_key)).to eq []
end
it "remembers unique message if specified" do
redis_service.push_msg(queue_name, "My message", remember_unique: true)
- expect(redis { |c| c.smembers unique_key }).to eq ["My message"]
+ expect(redis_call(:smembers, unique_key)).to eq ["My message"]
end
end
describe "#pluck" do
it "removes messages from queue" do
redis_service.push_msg(queue_name, "Message 1")
redis_service.push_msg(queue_name, "Message 2")
redis_service.pluck(queue_name, 2)
- expect(redis { |c| c.llen key }).to eq 0
+ expect(redis_call(:llen, key)).to eq 0
end
it "forgets unique messages", :aggregate_failures do
redis_service.push_msg(queue_name, "Message 1", remember_unique: true)
redis_service.push_msg(queue_name, "Message 2", remember_unique: true)
- expect(redis { |c| c.scard unique_key }).to eq 2
+ expect(redis_call(:scard, unique_key)).to eq 2
redis_service.pluck(queue_name, 2)
- expect(redis { |c| c.smembers unique_key }).to eq []
+ expect(redis_call(:smembers, unique_key)).to eq []
end
- end
-
- private
-
- def redis(&block)
- Sidekiq.redis(&block)
end
end