Rails 4.2: Test randomly fail on connecting to Redis


#1

Some of my tests fail randomly when the test case connects to redis with the following message:

Cannot assign requested address - connect(2) for [::1]:6379

my circle.ci is the following:

version: 2
jobs:
  build:
    docker:
    - image: getgambacom/centos7:1.0

    steps:
    - run:
        name: Starting Redis server
        command: |
          sed -e 's/^bind 127\.0\.0\.1$/bind 127.0.0.1 ::1/' < /etc/redis.conf > /tmp/redis.conf && mv /tmp/redis.conf /etc/redis.conf
          redis-server --daemonize yes
    - checkout
    - run:
        name: Run tests
        command: bin/test-runner

The error is not always occurred. Re-running the tests succeed in many cases.

Does anyone know how to fix this issue?


#2

Yes, your two containers will start in parallel, but “started” does not mean the software within is ready.

Put a new run step in before your tests to repeatedly try connecting to Redis, and either fail after a long timeout, or succeed and get to the next step.


#3

This support center article could be useful to you, it sounds related, and the solution suggested should work with redis.

You can also place a run step with a sleep command before the timeout as @halfer suggested.


#4

Thanks a lot! It worked!


#5

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.