mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Call Discourse.redis.flushdb after the end of each test (#29117)
There have been too many flaky tests as a result of leaking state in Redis so it is easier to resolve them by ensuring we flush Redis' database. Locally on my machine, calling `Discourse.redis.flushdb` takes around 0.1ms which means this change will have very little impact on test runtimes.
This commit is contained in:
committed by
GitHub
parent
44fe8c62d6
commit
ed6c9d1545
@@ -1,34 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RedisSnapshot
|
||||
def self.begin_faux_transaction(redis = Discourse.redis)
|
||||
@stack ||= []
|
||||
@stack.push(RedisSnapshot.load(redis))
|
||||
end
|
||||
|
||||
def self.end_faux_transaction(redis = Discourse.redis)
|
||||
@stack.pop.restore(redis)
|
||||
end
|
||||
|
||||
def self.load(redis = Discourse.redis)
|
||||
keys = redis.keys
|
||||
|
||||
values = redis.pipelined { |batch| keys.each { |key| batch.dump(key) } }
|
||||
|
||||
new(keys.zip(values))
|
||||
end
|
||||
|
||||
def initialize(dump)
|
||||
@dump = dump
|
||||
end
|
||||
|
||||
def restore(redis = Discourse.redis)
|
||||
redis.pipelined do |batch|
|
||||
batch.flushdb
|
||||
|
||||
@dump.each { |key, value| batch.restore(key, 0, value) }
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user