Aldana
Aldana

Reputation: 383

Sucker punch tests in rails, using connection_pool block, results in connection timeout

Thanks in advance for your kind response.

At work we are using sucker punch gem for a rails app to send emails and other stuff we want to do asynchronously.

We implemented a couple of actors with no problems and even wrote some tests for them successfully, using the recommended configuration for that matter (requiring sucker_punch/testing/inline in the specs and using truncation as database cleaning strategy).

Everything was working like a charm, until the last actor that we decided to implement. It has nothing different than the others, but now, when running the test suite, ActiveRecord::ConnectionTimeoutError is raised.

I've searched the internet for a solution but nothing came up. Most of the answers (like this one) would suggest to use ActiverRecord::Base.connection_pool.with_connection method passing a block to it. We were already doing that.

The only thing that I can think of is that we are handling errors on the actors, rescuing exceptions, like this:

def perform
  ActiveRecord::Base.connection_pool.with_connection do
    begin
      ... # do something
    rescue SomeException => e
      ... # handle exception
    end
  end
end

But looking at source this souldn't be a problem since with_connection has an ensure to release it.

I will be opening an issue on sucker punch and will be updating this question if I have some news.

The release in question can wait, but this also makes me wonder if we are having this same issue in production...

Cheers, Aldana.

EDIT The author of the gem told me that apparently there was nothing wrong with the code, and suggested to increase the pool size. I'm going to use this approach and if the error persists we will change some parts of the code not to use sucker punch.

Upvotes: 3

Views: 522

Answers (0)

Related Questions