Rails Parallel Testing and the flipper gem

Thomas Winkler
The Jade Mind
Published in
1 min readNov 29, 2021

Last week we updated our test suite to take advantage of the possibility to run tests in parallel. This feature was introduced in Rails 6 (see Guide).

With adding a single line in the test_helper.rb

we instantly benefit from a significant performance boost. However, we observe that some of our tests turn flaky so we took a closer look.

It turns out that the flipper gem (which by the way is an awesome gem for feature flagging) shares state across the tests running in parallel.

To fix this issue one option would be to mock the Flipper service in your tests. Another option (we choose because of less effort) is to use the flipper provided Flipper::Adapters::PStoreto create a pstore (PStore implements a file based persistence mechanism based on a Hash) for each sub process Rails starts to run the tests.

For this purpose we create a new Flipper instance based on the original Flipper instance in the parallelize_setup hook which will be called for each sub process. And here is the code:

--

--