Circle CI 2.0 Rails Redis Resque - Rspec Redis Server Not Found Error



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.

Any thoughts would be greatly appreciated!

enter image description here

Resque Initializer

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 = {
    port: uri.port,
    password: uri.password
  Resque::Failure::Multiple.classes = [ Resque::Failure::Redis, Resque::Failure::Rollbar ]
  Resque::Failure.backend = Resque::Failure::Multiple
  Resque.redis =
elsif AppUnsecure.settings[:active_db_services].include?('redis-continous-integration')
  Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
  Resque.redis = 'redis://localhost', port: 6391)
  Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
  Resque.redis =

Resque.redis.namespace = 'resque:GathrlySmartforms'

# Ignores Resque when processing jobs if activated!
Resque.inline = true if AppUnsecure.settings[:process_redis_inline]

# Setup Scheduler
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'
Resque::Scheduler.dynamic = true

schedules = {}
global = YAML.load_file("#{Rails.root}/config/resque_schedule.yml")
schedules.merge!(global) if global
unless defined?(is_running_migration?) && is_running_migration?
  Resque.schedule = schedules if schedules.present?

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]

Circle Configuration

version: 2
    working_directory: ~/DIR_NAME
      - image: circleci/ruby:2.4.1-node
          RAILS_ENV: continous_integration
          PGUSER: rails_test_user

      - image: circleci/postgres:9.6.3-alpine
          POSTGRES_USER: rails_test_user
          POSTGRES_DB: continous_integration

      - image: redis:4.0.6

      - checkout

      - run:
          name: Dockerize v0.6.0
          command: |
            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:
            - DIR_NAME-{{ checksum "Gemfile.lock" }}
            - DIR_NAME-

      - save_cache:
          key: rails-demo-{{ checksum "Gemfile.lock" }}
            - 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
            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>/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


On various test runs it may occasionally work…however, the error is still the same, this must be the cause…

enter image description here


It’s not your CircleCI configuration, it’s going to be in your bundle config. Based on the command you ran and the error you got, your specs are misconfigured to bring up Redis on start time.

There are two solutions:

  1. Remove redis-server from your bundle config
  2. Remove the Redis image from the top of the config.yml and install redis-server.

The first one is more ideal.



Thanks for your reply! My name is Andrew and I work with Chris as a junior on the project. I don’t have experience setting up a circle.yml before tooling with this configuration so you may have to be extra clear so that I can be sure what you mean.

Inside the circle.yml, we want to remove the redis image and install ‘redis-server’ as a step under a ‘run’ command?

When you say remove it from the bundle config, are you meaning the ‘.bundle’ bundler config file?

Thanks for your help!


I have no insight into your project but the command you’re running in that screenshot has nothing to do with Redis. Since you’re hitting an error with trying to start redis-server, it tells me you have bundle/rspec configured to start Redis when specs are run.


I took the whole “before suite” block out of the redis spec config. The suite is running and passing, and we’re still getting output about the kill -q being invalid, and the .pid not existing, but no error about redis-server not being found.

# frozen_string_literal: true

RSpec.configure do |config|
  # rubocop:disable Rails/FilePath
  REDIS_PID = "#{Rails.root}/tmp/pids/"
  REDIS_CACHE_PATH = "#{Rails.root}/tmp/cache/"
  # rubocop:enable all

  config.before(:suite) do
    redis_options = {
      'daemonize'     => 'yes',
      'pidfile'       => REDIS_PID,
      'port'          => 9_736,
      'timeout'       => 300,
      'save 900'      => 1,
      'save 300'      => 1,
      'save 60'       => 10_000,
      'dbfilename'    => 'dump.rdb',
      'dir'           => REDIS_CACHE_PATH,
      'loglevel'      => 'debug',
      'logfile'       => 'stdout',
      'databases'     => 16
    }.map { |k, v| "#{k} \"#{v}\"" }.join("\n")
    `echo '#{redis_options}' | redis-server -`

  config.after(:suite) do
      cat "#{REDIS_PID}" | xargs kill -QUIT
      rm -f "#{REDIS_CACHE_PATH}dump.rdb"

  config.before do


What is the exact command you’re running for kill, and what is running it? I assume it’s run by Rspec, since it’s not in your commands above.

In any case, I wonder if this would be a better question for Stack Overflow - it does not seem to be a CircleCI-specific problem, and there would be a wider audience over there to give you Rails-specific answers.