spec/routemaster/redis_broker_spec.rb in routemaster-drain-2.3.0 vs spec/routemaster/redis_broker_spec.rb in routemaster-drain-2.4.0
- old
+ new
@@ -4,53 +4,53 @@
describe Routemaster::RedisBroker do
subject { Class.new(Routemaster::RedisBroker).instance }
describe "#get" do
- let(:url) { 'redis://localhost/12' }
+ let(:urls) { ['redis://localhost/12'] }
context "setting up a redis namespace" do
- let(:redis) { instance_double(Redis) }
+ let(:redis) { instance_double(Redis, id: 1) }
let(:redis_namespace) { instance_double(Redis::Namespace) }
before do
- allow(Redis).to receive(:new) { redis }
+ allow(Redis::Distributed).to receive(:new) { redis }
allow(Redis::Namespace).to receive(:new) { redis_namespace }
end
it 'returns a namespaced redis connection' do
- expect(subject.get(url)).to eq(redis_namespace)
+ expect(subject.get(:name, urls: urls)).to eq(redis_namespace)
end
it 'uses the url to initialise redis' do
- expect(Redis).to receive(:new).with(url: url)
- subject.get(url)
+ expect(Redis::Distributed).to receive(:new).with(urls)
+ subject.get(:name, urls: urls)
end
it 'namespaces with rm by default' do
expect(Redis::Namespace).to receive(:new).with('rm', redis: redis)
- subject.get(url)
+ subject.get(:name, urls: urls)
end
it 'can use a namespace based on the url' do
expect(Redis::Namespace).to receive(:new).with('other', redis: redis)
- subject.get('redis://localhost/12/other')
+ subject.get(:name, urls: ['redis://localhost/12/other'])
end
end
context "when we are in the same process" do
it 'is a single connection for each url' do
- expect(subject.get(url)).to eql(subject.get(url))
+ expect(subject.get(:name, urls: urls)).to eql(subject.get(:name, urls: urls))
end
end
context "when we have forked" do
- let!(:connection) { subject.get(url) }
+ let!(:connection) { subject.get(:name, urls: urls) }
it 'is a new connection for the newly forked process' do
# this is tied to implementation, but tests a 'fork' well enough
allow(Process).to receive(:pid) { -1 }
- expect(subject.get(url)).to_not eql(connection)
+ expect(subject.get(:name, urls: urls)).to_not eql(connection)
end
end
end
end