title: Circle CI 2.0 Rails Redis Resque - Rspec Redis Server Not Found Error
body: <p>When our test suite runs we are getting the following issue regarding redis-server. No matter what we have tried, nothing seems to get past this error.  We have validated via dockerize that the containers are live by waiting as seen below, but this error still occurs. </p>
  
  <p>Any thoughts would be greatly appreciated!</p>
  
  <p><a href="https://i.stack.imgur.com/TWCjb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TWCjb.png" alt="enter image description here"></a></p>
  
  <p><strong>Resque Initializer</strong></p>
  
  <pre><code>require 'resque'
  require 'redis'
  require 'yaml'
  
  # Resque Plugins
  require 'resque/plugins/retry'
  require 'resque-retry'
  require 'resque-retry/server'
  require 'resque-lock-timeout'
  require 'resque-scheduler'
  require 'resque/failure/multiple'
  require 'resque/failure/redis'
  require 'resque-job-stats/server'
  require 'resque/rollbar'
  
  if AppUnsecure.settings[:active_db_services].include?('redis')
    uri = URI.parse(ENV["REDIS_URL"])
    config = {
      host: uri.host,
      port: uri.port,
      password: uri.password
    }
    Resque::Failure::Multiple.classes = [ Resque::Failure::Redis, Resque::Failure::Rollbar ]
    Resque::Failure.backend = Resque::Failure::Multiple
    Resque.redis = Redis.new(config)
  elsif AppUnsecure.settings[:active_db_services].include?('redis-continous-integration')
    Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
    Resque.redis = Redis.new(host: 'redis://localhost', port: 6391)
  else
    Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
    Resque.redis = Redis.new
  end
  
  Resque.redis.namespace = 'resque:GathrlySmartforms'
  
  # Ignores Resque when processing jobs if activated!
  Resque.inline = true if AppUnsecure.settings[:process_redis_inline]
  
  # Setup Scheduler
  # https://github.com/resque/resque-scheduler/issues/118
  # https://github.com/resque/resque-scheduler/issues/581
  Resque::Scheduler.configure do |c|
    c.quiet = false
    c.verbose = false
    c.logfile = File.join(Rails.root, 'log', "#{Rails.env}_resque_scheduler.log")
    c.logformat = 'text'
  end
  Resque::Scheduler.dynamic = true
  
  schedules = {}
  global = YAML.load_file("#{Rails.root}/config/resque_schedule.yml")
  schedules.merge!(global) if global
  # http://stackoverflow.com/questions/12158226/how-do-i-skip-loading-of-rails-initializers-when-running-a-rake-task
  unless defined?(is_running_migration?) &amp;&amp; is_running_migration?
    Resque.schedule = schedules if schedules.present?
  end
  
  Resque::Server.class_eval do
    use Rack::Auth::Basic do |username, password|
      [username, password] == [Rails.application.secrets.my_resque_username, Rails.application.secrets.my_resque_password]
    end
  end
  </code></pre>
  
  <p><strong>Circle Configuration</strong></p>
  
  <pre><code>version: 2
  jobs:
    build:
      working_directory: ~/DIR_NAME
      docker:
        - image: circleci/ruby:2.4.1-node
          environment:
            RAILS_ENV: continous_integration
            PGHOST: 127.0.0.1
            PGUSER: rails_test_user
  
        - image: circleci/postgres:9.6.3-alpine
          environment:
            POSTGRES_USER: rails_test_user
            POSTGRES_PASSWORD: ""
            POSTGRES_DB: continous_integration
  
        - image: redis:4.0.6
  
      steps:
        - checkout
  
        - run:
            name: Dockerize v0.6.0
            command: |
              wget https://github.com/jwilder/dockerize/releases/download/v0.6.0/dockerize-linux-amd64-v0.6.0.tar.gz
              sudo rm -rf /usr/local/bin/dockerize
              sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.6.0.tar.gz
              rm dockerize-linux-amd64-v0.6.0.tar.gz
  
        - run:
            name: Wait for PG
            command: dockerize -wait tcp://localhost:5432 -timeout 2m
  
        - run:
            name: Wait for Redis
            command: |
              dockerize -wait tcp://localhost:6379 -timeout 2m
  
        - restore_cache:
            keys:
              - DIR_NAME-{{ checksum "Gemfile.lock" }}
              - DIR_NAME-
  
        - save_cache:
            key: rails-demo-{{ checksum "Gemfile.lock" }}
            paths:
              - vendor/bundle
  
        - run:
            name: Setup Bundler and Gems
            command: |
              gem install bundler
              gem update bundler
              gem install brakeman
              gem install rubocop
              gem install rubocop-rspec
              gem install scss_lint
              gem install eslint-rails
              gem install execjs
              bundle config without development:test
              bundle check --path=vendor/bundle || bundle install --without development test --path=vendor/bundle --jobs 4 --retry 3
  
        - run:
            name: Install Phantom Js
            command: |
              sudo curl --output /tmp/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
              sudo chmod ugo+x /tmp/phantomjs
              sudo ln -sf /tmp/phantomjs /usr/local/bin/phantomjs
  
        - run:
            name: Install Postgres Tools
            command: |
              sudo apt-get update
              sudo apt-get install postgresql-client
  
        - run:
            name: Install Redis Tools
            command: |
              sudo apt-get install redis-tools ; while ! redis-cli ping 2&gt;/dev/null ; do sleep 1 ; done
  
        - run:
            name: Build Rails Database Yaml
            command: |
              cp config/database_example.yml config/database.yml
  
        - run:
            name: Setup Rails Database
            command: |
              bundle exec rake db:drop
              bundle exec rake db:setup
  
        - run:
            name: Run Rspec
            timeout: 60
            command: |
              RAILS_ENV=continous_integration bundle exec rspec --format RspecJunitFormatter -o /tmp/test-results/rspec.xml
  
        - run:
            name: Run Brakeman
            command: |
              brakeman -z
  
        - run:
            name: Run Rubocop
            command: |
              bundle exec rubocop --format fuubar --require rubocop-rspec --config .rubocop.yml
  
        - run:
            name: Run the SCSS Linter
            command: |
              bundle exec scss-lint --config=config/scsslint.yml
  
        - run:
            name: Run the Eslint Linter for JS
            command: |
              bundle exec rake eslint:run_all
  
  
        - store_test_results:
            path: /tmp/test-results
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>On various test runs it may occasionally work...however, the error is still the same, this must be the cause... </p>
  
  <p><a href="https://i.stack.imgur.com/LEBPj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LEBPj.png" alt="enter image description here"></a></p>