简体   繁体   中英

Ruby on Rails and Sidekiq redis connection pool with parallel tests?

I want to run my Rails tests in parallel. I'm currently using Sidekiq own connection pool to communicate with redis. The problem here is that if I run parallel tests they collide with each other. Rails has a very nice built in test database system that creates database clones of postgresql for each thread that executes the tests. How would I do that with Sidekiq redis connection pool?

Your tests shouldn't be connecting to redis at all. Much like how emails are handled in the test environment, by default Sidekiq will use fake queues for any scheduled jobs in the test environment.

Basically - running your tests in parallel will not cause you any issues with Sidekiq jobs.

You should start by reading the documentation on testing - https://github.com/mperham/sidekiq/wiki/Testing

Essentially, you can test to see if a job has been scheduled with something like this:

HardWorker.perform_async(1, 2)
HardWorker.perform_async(2, 3)
assert_equal 2, HardWorker.jobs.size

And if you need the jobs to run, just drain the queue:

HardWorker.drain
assert_equal 0, HardWorker.jobs.size

More details on the link above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM