Correct flaky distributed cache test

make distributed cache more testable
This commit is contained in:
Sam
2017-08-01 16:11:48 -04:00
parent 513b7bf706
commit 71ad3a48c2
2 changed files with 121 additions and 95 deletions

View File

@ -4,20 +4,30 @@ require 'distributed_cache'
describe DistributedCache do
before :all do
$redis.flushall
@bus = MessageBus::Instance.new
@bus.configure(backend: :memory)
@manager = DistributedCache::Manager.new(@bus)
end
after :all do
@bus.destroy
end
def cache(name)
DistributedCache.new(name, @manager)
end
let! :cache1 do
DistributedCache.new("test")
cache("test")
end
let! :cache2 do
DistributedCache.new("test")
cache("test")
end
it 'allows us to store Set' do
c1 = DistributedCache.new("test1")
c2 = DistributedCache.new("test1")
c1 = cache("test1")
c2 = cache("test1")
set = Set.new
set << 1
@ -45,8 +55,8 @@ describe DistributedCache do
end
it 'does not leak state across caches' do
c2 = DistributedCache.new("test1")
c3 = DistributedCache.new("test1")
c2 = cache("test1")
c3 = cache("test1")
c2["hi"] = "hi"
wait_for do
c3["hi"] == "hi"