Ruby 2.3-Browsers: Tests randomly fail with Error on CircleCI 2.0

selenium
circle.yml

#1

Some of my tests fail all the time with the following error:
Errno::EADDRNOTAVAIL: Failed to open TCP connection to localhost:9200 (Cannot assign requested address - connect(2) for "localhost" port 9200)

It feels like the test before has not closed its connection so that this test couldn’t be executed. They are both Selenium and Unit tests.

My test setup is the following:

 test:
    docker:
      - image: circleci/ruby:2.3-browsers
        environment:
          DB_HOST: 127.0.0.1
          DB_NAME: db
          DB_USER: u
          DB_PW:
          RAILS_ENV: test
      - image: circleci/postgres:9.6-alpine
        environment:
          POSTGRES_USER: u
          POSTGRES_DB: db
          POSTGRES_PASSWORD:
    steps:
      - checkout
      - run:
          name: Install gems
          command: |
            bundle install --path vendor/bundle --without development production
      - run:
          name: Setup DB
          command: |
            rails db:create
            rails db:schema:load
      - run:
          name: Run tests
          command: rake

Does anyone know how to fix the issue?


#2

Port 9200 is elasticsearch. My first guess is that your Rails codebase contacts elasticsearch but you’re not doing anything to provide an elasticsearch server to your Rails code. You can do that by adding in another docker image:

test:
  docker:
      - image: docker.elastic.co/elasticsearch/elasticsearch:6.0.0

#3

Thanks a lot. I totally forgot about this


#4