4

I have a project that is using CicleCI for testing, and I'm trying to integrate Tire for a search functionality. Locally, all the tests run fine with no issue. However, when CircleCI runs the test, I'm getting a Errno::ECONNREFUSED : Connection refused - connect(2) error. I've tried adding a 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 a circle.yml file as seen here: https://circleci.com/docs/config-sample

hosts:
    circlehost: 127.0.0.1

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

If anyone could help, it would be greatly appreciated.

justindao
  • 2,273
  • 4
  • 18
  • 34

2 Answers2

0

Since elasticsearch is available on local machine, the test cases will run fine. But on CircleCI you need to specify explicitly that elasticsearch is needed. Hence, you need to add 'elasticsearch' under services in circle.yml.

In circle.yml

machine:
  services:
    - elasticsearch

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

Prasad Surase
  • 6,486
  • 6
  • 39
  • 58
0

Note elasticsearch version used by default (when setting service:elasticsearch) is 0.92.0 (2 years old)

You can however install custom version of elasticsearch. And don't forget to remove elasticsearch from the "service" field.

However the elasticsearch may take some time to be available, so you will need to write a script to retry to connect.

Here is an example using the nodejs sdk: this code is in the before all hook of my testsuite:

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);
})
laurent
  • 2,590
  • 18
  • 26