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

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


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.


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);})