Redis and RSpec: Redis returning wildly inconsistent results

Hi list

I use Redis heavily in my application, and perform all of my unit
testing
using RSpec. So very often during my tests, I am hitting Redis
repeatedly.

I find that Redis repeatedly returns inconsistent and unexpected values
for
keys in my test environment. So every time I run a suite of specs, a few
of
them fail, seemingly randomly. The specs are usually very simple, and
often
just testing the contents of simple string keys in Redis. The results
seem
like they might come from a different object or instance variable of the
same type/name: so they’re always seemingly valid values, but don’t
actually
relate to the spec currently being performed. So the spec fails.

This is really reducing the value of my tests, because I can never tell
if
they’re really failing or not without digging into them.

I’ve tried all sorts of things to fix this so far, including setting the
:thread_safe option for Redis in my test environment (no difference),
and
forcing a reconnection to Redis before each suite of specs (no
difference).

I’m pretty sure this is a problem with the connection between RSpec and
Redis, or some kind of threading issue, but I can’t be 100% sure even of
that. I’m at a little bit of a loss.

Anybody experienced anything similar?

On Mon, Jan 17, 2011 at 7:14 PM, Rob W. [email protected] wrote:

Hi list

I find that Redis repeatedly returns inconsistent and unexpected values for keys
in my test environment. So every time I
run a suite of specs, a few of them fail, seemingly randomly. The specs are
usually very simple, and often just testing
the contents of simple string keys in Redis. The results seem like they might
come from a different object or instance
variable of the same type/name: so they’re always seemingly valid values, but
don’t actually relate to the spec currently
being performed. So the spec fails.
[snip]
Anybody experienced anything similar?

This happened to me but before I setup redis to use a different
database for my test environment.

I have a specific redis.yml that contains this:

development:
url: redis://localhost:6769/0

test:
url: redis://localhost:6769/1

In that way, databases are keep separated from each other.

It is also important that you flush all the keys of your redis
instance between tests. Similar to what RSpec does for your database,
you need to perform it for redis.

I do it using a before(:each) { $redis.flushall }

Just to ensure integrity and no leftover from my previous test.

Will be great if you can show a little bit about your specs (exact
spec code) and configuration so we can try replicate. Sometimes the
error is there, but hidden somewhere else.

Luis L.
AREA 17

Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupry

Thanks Luis

I’ve just run my entire suite of specs 3 times and got 3 identical sets
of
results for the first time in a long time :slight_smile: