CIRCLE CI: --- Redis::CannotConnectError: - redis

When I run my rspec tests locally everything passes, but when I run them on Circle CI I get the rspec error: Redis::CannotConnectError:.
I recently added feature tests for SideKiq. It uses Redis and Chrome Driver.
I think I need to add the redis build into my cimg, but not sure how to do that.
Rspec Test Results
Failures:
1) Sidekiq::Web with admin user can able to access sidekiq GUI
Failure/Error: raise CannotConnectError, "Error connecting to Redis on #{location} (#{error.class})"
Redis::CannotConnectError:
Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:362:in `rescue in establish_connection'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:343:in `establish_connection'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:107:in `block in connect'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:308:in `with_reconnect'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:106:in `connect'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:381:in `ensure_connected'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:233:in `block in process'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:320:in `logging'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:232:in `process'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:126:in `call'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:305:in `block in info'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:69:in `block in synchronize'
# /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
# /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:69:in `synchronize'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:304:in `info'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq.rb:120:in `block in redis_info'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq.rb:98:in `block in redis'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/connection_pool-2.2.3/lib/connection_pool.rb:63:in `block (2 levels) in with'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/connection_pool-2.2.3/lib/connection_pool.rb:62:in `handle_interrupt'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/connection_pool-2.2.3/lib/connection_pool.rb:62:in `block in with'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/connection_pool-2.2.3/lib/connection_pool.rb:59:in `handle_interrupt'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/connection_pool-2.2.3/lib/connection_pool.rb:59:in `with'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq.rb:95:in `redis'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq.rb:114:in `redis_info'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/helpers.rb:171:in `redis_info'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/application.rb:46:in `block in <class:WebApplication>'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/application.rb:296:in `instance_exec'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/application.rb:296:in `block in call'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/application.rb:294:in `catch'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/application.rb:294:in `call'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/csrf_protection.rb:52:in `admit'
# /home/circleci/project/vendor/bundle/ruby/2.7.0/gems/sidekiq-6.1.2/lib/sidekiq/web/csrf_protection.rb:41:in `call'
# --- Caused by: ---
# IO::EINPROGRESSWaitWritable:
# Operation now in progress - connect(2) would block
# /usr/local/lib/ruby/2.7.0/socket.rb:1214:in `__connect_nonblock'
config.yml for CirclCI
version: 2.1
orbs:
browser-tools: circleci/browser-tools#1.1
jobs:
build:
parallelism: 1
docker:
- image: cimg/ruby:2.7.3-browsers
environment:
BUNDLE_JOBS: 3
BUNDLE_RETRY: 3
BUNDLE_PATH: vendor/bundle
PGHOST: 127.0.0.1
PGUSER: myapp
RAILS_ENV: test
CAPYBARA_DEFAULT_MAX_WAIT_TIME: 10
- image: circleci/postgres:9.5-alpine # database image
environment: # environment variables for database
POSTGRES_USER: myapp
POSTGRES_DB: myapp
POSTGRES_PASSWORD: mypass
steps:
- browser-tools/install-browser-tools
- checkout
- run:
name: Install NVM
command: |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash && \
export NVM_DIR="$HOME/.nvm" && \
echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV && echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV && \
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" && \
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
- run:
name: Install NodeJS
command: nvm install 8.9.1
- run:
name: Install bundler 2.0.2
command: gem install bundler:2.0.2
- run:
name: Which bundler?
command: bundle -v
- run:
name: Which Google Chrome?
command: google-chrome --version
- restore_cache:
keys:
- myapp-{{ checksum "Gemfile.lock" }}
- myapp-
- run:
name: Bundle Install
command: bundle check || bundle install
- save_cache:
key: myapp-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Database setup
command: bin/rails db:drop && bin/rails db:create && bin/rails db:migrate
- run:
name: Precompile Assets
command: bundle exec rake assets:precompile
- run:
name: Run rspec
command: bundle exec rspec spec

In the test environment, typically it's best not to queue jobs in Redis at all. This doc has info on how to configure Sidekiq in your tests.
https://github-wiki-see.page/m/mperham/sidekiq/wiki/Testing

Related

Tests in circleci wont pass after upgrading ruby and heroku to 20 from 18

I am currently working on an app that uses ruby on rails on the backend and react.js on the front end.
Since Heroku 18 is ending, I decided to start the upgrade to Heroku 20 which will be available till 2025. Since doing so, I have been banging my head against the wall for 2 days. I have updated my dependancies as I believe fit based on documentation, but now 3 of my tests keep failing (using selenium-webdriver, webdriver, and capybarra). The error thrown shows this:
Failures:
1) Posts create post
Failure/Error: fill_in :user_email, with: user.email
Capybara::ElementNotFound:
Unable to find visible field :user_email that is not disabled
# ./spec/support/auth_helper.rb:5:in `login_as'
# ./spec/features/beneficiary/posts/post_spec.rb:7:in `block (2 levels) in <main>'
# ./spec/rails_helper.rb:46:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:45:in `block (2 levels) in <top (required)>'
2) donor dashboard should have nav elements
Failure/Error: fill_in :user_email, with: user.email
Capybara::ElementNotFound:
Unable to find visible field :user_email that is not disabled
# ./spec/support/auth_helper.rb:5:in `login_as'
# ./spec/features/donor/dashboard_spec.rb:7:in `block (2 levels) in <main>'
# ./spec/rails_helper.rb:46:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:45:in `block (2 levels) in <top (required)>'
3) Posts create post
Failure/Error: fill_in :user_email, with: user.email
Capybara::ElementNotFound:
Unable to find visible field :user_email that is not disabled
# ./spec/support/auth_helper.rb:5:in `login_as'
# ./spec/features/donor/posts/post_spec.rb:7:in `block (2 levels) in <main>'
# ./spec/rails_helper.rb:46:in `block (3 levels) in <top (required)>'
# ./spec/rails_helper.rb:45:in `block (2 levels) in <top (required)>'
In the file auth_helper, the format for the fill_in seems to be the issue, but looking at the documentation and confirming the id for user_email to be correct, I don't really understand what is happening at all. I feel like this might be a red herring as it really doesn't seem to be an issue on other tests that use the same method login_as. I tried upping the capybarra timeout time limit as well, and it still seems to fail to the page is certainly loading.
These tests are also passing locally, and only fail when i run them through circleci, which has me baffled and without much understanding of what to try next.
def login_as(user, password: "password")
visit root_path
find('a', text: 'Login').click
fill_in :user_email, with: user.email
fill_in :user_password, with: password
find("input[value='Log in']").click
end
The referenced lines in rails_helper are databaseCleaner and example run lines below:
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
My config.yml is:
# CircleCI 2.0 configuration file
version: 2.1
orbs:
browser-tools: circleci/browser-tools#1.4.0
jobs:
build:
docker:
# specify the version you desire here
- image: cimg/ruby:3.0.5-browsers # circleci/ruby:2.7.0-node-browsers
environment:
PGHOST: 127.0.0.1
PGUSER: $HEROKU_APP_NAME
RAILS_ENV: test
BUNDLER_VERSION: 2.0.2
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/postgres:9.5-alpine
environment:
POSTGRES_USER: $HEROKU_APP_NAME
POSTGRES_DB: $HEROKU_APP_NAME_test
POSTGRES_PASSWORD: $HEROKU_APP_NAME
- image: redis:4.0.10
working_directory: ~/repo
steps:
- checkout
- browser-tools/install-browser-tools
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Swap node versions
command: |
set +e
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install v14
nvm alias default 14.21.1
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
- run:
name: Configure Bundler
command: |
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
source $BASH_ENV
gem install bundler
- run:
name: install dependencies
command: |
bundle config set --local path 'vendor/bundle'
bundle install --jobs=4 --retry=3
# --path vendor/bundle
- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
# Database setup
- run: bundle exec rails db:create
- run: bundle exec rails db:schema:load
# frontend
- restore_cache:
keys:
- sell-more-yarn-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
- sell-more-yarn-cache-{{ .Branch }}-
- sell-more-yarn-cache-
- run:
name: Yarn Install
command: |
yarn --ignore-engines --cache-folder ~/.cache/yarn
- save_cache:
key: sell-more-yarn-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- run:
name: Webpacker Pre-Compile
command: bundle exec rails webpacker:compile
# run tests!
- run:
name: run tests
command: |
bundle exec rspec --profile 10 \
--out test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
# collect reports
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results
destination: test-results
workflows:
version: 2
build-and-deploy:
jobs:
- build
Versions:
ruby '3.0.5'
gem 'rails', '~> 6.1'
group :test do
gem 'capybara', '~> 3.38'
gem 'database_cleaner'
gem 'factory_bot_rails', '~> 6.2.0'
gem 'rack_session_access'
gem 'rails-controller-testing'
gem 'rspec-rails'
gem 'selenium-webdriver', '~> 4.0'
gem 'shoulda-callback-matchers', '~> 1.1.1'
gem 'shoulda-matchers', '~> 4.4'
gem 'spring-commands-rspec'
gem 'stripe-ruby-mock', github: 'rebelidealist/stripe-ruby-mock'
gem 'timecop'
gem 'webdrivers', '~> 5.2'
gem 'webmock'
end
Anyone have any ideas to help me get past this as I am falling behind on time and could really use a point in the right direction!
Thanks in advance!
I am expecting these tests to pass as they can locally and should be able to on circleci as they were right before the upgrade.

Running into issues installing gitlab-shell

I am trying to install Gitlab CE from source and following this installation guide.
When I attempt to install the gitlab-shell using the command provided.
sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true
I received the following stack trace error.
WARNING: This version of GitLab depends on gitlab-shell 4.1.1, but you're running Unknown. Please update gitlab-shell.
rake aborted!
Gitlab::TaskFailedError: Gitlab::TaskFailedError
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:87:in `run_command!'
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:164:in `clone_repo'
/home/git/gitlab/lib/tasks/gitlab/task_helpers.rb:157:in `checkout_or_clone_tag'
/home/git/gitlab/lib/tasks/gitlab/shell.rake:16:in `block (3 levels) in <top (required)>'
/usr/local/bin/bundle:22:in `load'
/usr/local/bin/bundle:22:in `<main>'
Tasks: TOP => gitlab:shell:install
What config file should I be modifying to fix my issue? Do I need to modify the Redis URL even though I am using the default configuration? By the way, this install is on an Ubuntu 16.04 server.
This might be caused by using a version of git that is too old.
To debug: append the --trace option to bundle exec to get more info on where this error is coming from and inspect the source.

Installed ruby gem(NMatrix) not showing in irb

I have installed ruby gem nmatrix with the command below:
sudo gem install nmatrix
I have installed it in ubuntu 12.04 . My gem env is as below:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.9.3 (2013-05-15 patchlevel 429) [i686-linux]
- INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p429
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.3-p429/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-1.9.3-p429/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/local/rvm/gems/ruby-1.9.3-p429
- /usr/local/rvm/gems/ruby-1.9.3-p429#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.github.com/", "http://rubygems.org"]
- REMOTE SOURCES:
- http://gems.github.com/
- http://rubygems.org
Now when I go to irb and run code as below,to use NMatrix it gives error as :
irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'nmatrix'
LoadError: cannot load such file -- nmatrix
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):2
from /usr/local/rvm/rubies/ruby-1.9.3-p429/bin/irb:13:in `<main>'
irb(main):003:0>
So what should I do to use nMatrix gem I just installed. Also when i do
gem list
It is not showing nmatrix gem.
Doing
sudo gem list
only shows nmatrix gem.
Thanks.

Docker + Rspec + Capybara - arguments[0] is undefined

I'm trying to get my specs working headlessly in docker - They run fine locally on my mac but when I run them inside the docker container I get this error (repeated multiple times)
Selenium::WebDriver::Error::JavascriptError:
arguments[0] is undefined
# [remote server] https://foobar.com/ line 68 > Function:1:1:in `anonymous'
# [remote server] https://foobar.com/:68:20:in `handleEvaluateEvent'
# ./spec/features/foo_spec.rb:15:in `block (2 levels) in <top (required)>
Xvfb is running: Xvfb :99.0 -screen 0 1366x768x16
I've also tried doing a xvfb-run rspec and got the same errors.
spec_helper.rb:
Capybara.default_driver = :selenium
Capybara.javascript_driver = :selenium
What's going on that this can't run inside docker?
The reason for this error is this:
>> webdriver.execute_script("return typeof arguments[0]", "foo")
=> "undefined"
Apparently this is a bug with Firefox 35 and webdriver. There is an issue open for it - https://code.google.com/p/selenium/issues/detail?id=8390.

Unicorn with Foreman - Socket Already Used Error

I want to control the unicorn process with in foreman procfile. Here is my Procfile
web: bundle exec unicorn -c config/unicorn/local.rb -E local
thinking_sphinx: bundle exec rake ts:start
delayed_job: ./script/delayed_job start
delayed_delta: ./script/delayed_delta start
mail_receiver: ./scripts/mail_receiver_runner start
Here is my unicorn config.
app_path = /home/deploy/apps/local.myapp.com/myapp/current
worker_processes 1
preload_app false
timeout 180
listen "#{app_path}/tmp/pids/unicorn.sock", backlog: 1024
pid "#{app_path}/tmp/pids/unicorn.pid"
working_directory app_path
stderr_path "log/unicorn.log"
stdout_path "log/unicorn.log"
When I start it with cap foreman:start it is raising these errors:
adding listener failed addr=/home/deploy/apps/local.myapp.com/myapp/current/tmp/pids/unicorn.sock (in use)
/home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/socket_helper.rb:140:in `initialize': Address already in use - /home/deploy/apps/local.myapp.com/myapp/current/tmp/pids/unicorn.sock (Errno::EADDRINUSE)
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/socket_helper.rb:140:in `new'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/socket_helper.rb:140:in `bind_listen'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:228:in `listen'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:751:in `block in bind_new_listeners!'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:751:in `each'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:751:in `bind_new_listeners!'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:140:in `start'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/bin/unicorn:121:in `<top (required)>'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load'
from /home/deploy/apps/local.myapp.com/myapp/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>'
Is it related to unicorn or a configuration issue for foreman?
Removing this line from unicorn configuration sort out the issue.
pid "#{app_path}/tmp/pids/unicorn.pid"