I'm currently trying to upgrade a Rails 3.2 app to Rails 4.0.13 (ruby 2.3.5, PostgreSQL 9.4.13) and I'm getting this error when running my integration tests;
: PG::UnableToSend at /companies/get_current_firm
: ===============================================
:
: > socket not open
:
:
: activerecord (4.0.13) lib/active_record/connection_adapters/postgresql_adapter.rb, line 798
: -------------------------------------------------------------------------------------------
:
: ``` ruby
: 793 end
: 794
: 795 FEATURE_NOT_SUPPORTED = "0A000" #:nodoc:
: 796
: 797 def exec_no_cache(sql, binds)
: > 798 @connection.async_exec(sql, [])
: 799 end
: 800
: 801 def exec_cache(sql, binds)
: 802 stmt_key = prepare_statement sql
: 803
: ```
This integration test logs in and then there is a number of calls from the frontend (AngularJS) to get details like the current firm selected, etc. Each one of these calls gets the same message, it's like the connection has been shutdown. I'm using the chrome browser through selenium & capybara in LIVE mode so I can see what is happening.
Here is my database.yml file for test
test: &test
adapter: postgresql
encoding: unicode
database: test_<%= ENV['USER'] %><%= ENV['TEST_ENV_NUMBER'] %>
pool: 5
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
Here is the call it is making from the frontend
AngularJS
current_firm: (scope) ->
$http({method: 'GET', url: '/companies/get_current_firm'}).success (data) ->
scope.current_firm = data['firm']
Rails Controller
def get_current_firm
render json: {firm: current_firm.organisation}
end
There are three separate calls to get different data when a user logs in, sometimes in the tests it will get 1 or 2 of them but never three.
I tried the work around from http://www.ruby-railings.com/en/rails/postgresql/2014/01/11/connection-problems-in-rails-4.html. This didn't fix the problem at all.
Update
When the user logs in there are three http calls fired off from AngularJS to the Rails backend. If I remark out two of the calls then that call works every time. If I remark out only one, so we have two calls then it fails one or both of the calls. I get a 'pending' message on one of the calls.
I've worked that this was an AngularJS problem sending too many requests to Rails 4 at once. To fix the problem I put each call in a promise.