Rails, Tire, and CircleCI: getting Errno :: ECONNREFUSED error when running rspec tests when creating Tire-Searchable objects

I have a project that uses CicleCI for testing, and I'm trying to integrate Tire for search. Locally, all tests pass normally, without problems. However, when CircleCI starts the test, I get the error Errno::ECONNREFUSED : Connection refused - connect(2) . I tried adding the tire.rb file to config / initilizers:

 if Rails.env.test? ENV['ELASTICSEARCH_URL'] = "http://circlehost:9200" # With and without this. Tire.configure do url "http://circlehost:9200" # also tried localhost:9200, and 127.0.0.1:9200 end end 

Tried adding circle.yml file as shown here: https://circleci.com/docs/config-sample

 hosts: circlehost: 127.0.0.1 

And any combination of them. Now I have no ideas, and I have no idea what to do. I thought I was on the right track, but now I'm not sure.

If anyone can help, he will be very grateful.

+4
source share
2 answers

Since elasticsearch is available on the local machine, test cases will work fine. But in CircleCI, you need to explicitly state that elasticsearch is needed. Therefore, you need to add "elasticsearch" under the services in circle.yml.

In circle.yml

 machine: services: - elasticsearch 

checkout https://circleci.com/docs/configuration#services for more information.

0
source

Note. The default version of elasticsearch (when configuring the service: elasticsearch) is 0.92.0 (2 years)

However, you can install a custom version of elasticsearch . And don't forget to remove elasticsearch from the "service" field.

However, elasticsearch may take some time to search, so you will need to write a script to reconnect.

Here is an example using nodejs sdk: this code is at the end of my hookuite:

 before(function(done){ var count = 1; function _setup (c) { return client.ping({pingTimeout: 4000}) .then(function () { done(); }) .catch(function (err) { console.log(err); console.log('retry ', c); return setTimeout(function () { _setup(count++); }, 4000); }); } _setup(count); }) 
0
source

Source: https://habr.com/ru/post/1490921/


All Articles