contribsys / faktory_worker_ruby

Faktory worker for Ruby
GNU Lesser General Public License v3.0
214 stars 31 forks source link

Advice on Integration Tests #76

Closed improbablistic closed 1 year ago

improbablistic commented 1 year ago

I would like to get advice on how to perform integration test (more detail on what I mean below) that involves Rails and Faktory.

Set Up

I have a project that boils down to the following:

Test Case

  1. Daemon sends jobs to faktory
  2. Faktory ruby worker processes, updates DB and sends ActionCable broadcast
  3. UI is updated

I am hoping to create integration tests that will run a the mentioned live and make use of the test API offered by rails. In particular, I am wondering if it is possible to set up test instance of Faktory worker that accesses Minitest DB Transaction used in system test?

Thank you.

mperham commented 1 year ago

Transactions are per-process. I don't know how you could have a system test process (e.g. Capybara driving a web browser) running a transaction in a controller action which is visible to a separate FWR process. You could schedule the job to run in one second and have the controller transaction commit so the job can see the transactional data.

improbablistic commented 1 year ago

Thanks for the feedback, my current approach is to set up a custom rails environment where integration tests will not use transactional fixture. This way, both worker process and rails server will update the same test database.

Not the most elegant solution, but I suppose it will work for the time being.