Skip to content

:only Strategy is Broken #12

Open
@jherdman

Description

@jherdman

During test runs I namespace all Redis operations under "test:* using the redis-namespace Gem. Let's check to see if it works if I configure only: ["test*"]:

$ redis-cli set 'foo' 'bar'
OK
$ redis-cli keys '*'
1) "foo"
$ bin/rspec path/to/spec
# ASSUME TESTS RUN...
$ redis-cli keys '*'
(empty array)

Uh oh! We've accidentally wiped every single key in the Redis DB. This is a bummer for my development environment.

I've tracked this down to this bit of code:

only = expand_keys(@only)
except = expand_keys(@except)
only = connection.keys if only.none?
(only - except)

  1. On L26 we don't find any keys in the "test:*" namespace as expected. Ergo only == []
  2. except: isn't configured, ergo except == []
  3. only.none? is true, therefore we go ahead and find all keys in the Redis DB (bug!!)
  4. (only - except) returns every single key in the Redis DB, and they're then dutifully wiped out

A reproduction PR: #13

I was hoping we could simply drop L28 but it seems like there's existing behaviour that relies upon this logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions