Rails 4.2: Test randomly fail on connecting to Redis

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
    - image: getgambacom/centos7:1.0

    - run:
        name: Starting Redis server
        command: |
          sed -e 's/^bind 127\.0\.0\.1$/bind ::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?

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.

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.

Thanks a lot! It worked!


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