I'm having a weird issue where I'm testing a controller that has a procedure that uses caching. The test is failing, but if I do a binding.pry
inside the method that does the caching, the test passes.
example of the method containing the caching and the binding.pry:
def method_example:
data = Rails.cache.fetch(cache_key) do
ProcedureService.new(params).generate
end
binding.pry
data
end
Example of the test:
it "reverts record amount" do
expect(record.amount).to eq((original_amount + other_amount).to_d)
end
The caching is done via redis_store.
When done in the development environment, it works fine. What I don't understand is why it is failing but passing when adding a stopper? It seems it could be something about the time it takes to fetch the cache
UPDATE
Using sleep, instead of binding.pry also makes the test pass, so I can assume this is a timing issue. What is the problem exactly? and how could I manage it?