spec/routemaster/redis_broker_spec.rb in routemaster-drain-2.5.2 vs spec/routemaster/redis_broker_spec.rb in routemaster-drain-2.5.3
- old
+ new
@@ -2,14 +2,13 @@
require_relative '../../lib/routemaster/redis_broker'
describe Routemaster::RedisBroker do
subject { Class.new(Routemaster::RedisBroker).instance }
+ let(:urls) { ['redis://localhost/12'] }
describe "#get" do
- let(:urls) { ['redis://localhost/12'] }
-
context "setting up a redis namespace" do
let(:redis) { instance_double(Redis, id: 1) }
let(:redis_namespace) { instance_double(Redis::Namespace) }
before do
@@ -49,8 +48,33 @@
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(:name, urls: urls)).to_not eql(connection)
end
+ end
+ end
+
+ describe "#inject_clients" do
+ let(:drain_client) { instance_double(Redis) }
+ let(:cache_client) { instance_double(Redis) }
+
+ before do
+ # Reset the singleton
+ Routemaster::RedisBroker.instance_exec { @singleton__instance__ = nil }
+
+ subject.inject(drain_client: drain_client, cache_client: cache_client)
+ end
+
+ it "sets stores the provided clients for later use" do
+ drain = subject.get(:drain_client, urls: urls)
+ expect(drain).to be_a(Redis::Namespace)
+ expect(drain.namespace).to eql 'rm'
+ expect(drain.redis).to eql drain_client
+
+
+ cache = subject.get(:cache_client, urls: urls)
+ expect(cache).to be_a(Redis::Namespace)
+ expect(cache.namespace).to eql 'rm'
+ expect(cache.redis).to eql cache_client
end
end
end