In my application, I have several Builder classes that are responsible for receiving data received from an external API request and creating / saving resources in the database. I deal with a lot of data and implemented a Parallel gem to speed this up using several processes.
However, I found that any test for a method that uses Parallel fails with the same error:
ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
Here is an example of test code:
class AirportBuilder < Resource def build_from_collection Parallel.each(object_producer, in_processes: 24) do |params| instance = Airport.find_or_initialize_by(fsid: params[:fs]) build!(instance, params) end end end
I did a few searches on this, but all of the results on Google use multiple threads / processes to make the test suite faster, which is another problem.
Any ideas on how I can test this efficiently without causing PG errors? I understand that I might need to drown something, but I'm not quite sure what to drown and still have a meaningful test.
Thanks in advance to everyone who can help!
source share