redis - CIRCLE CI: --- Redis::CannotConnectError:
问题描述
当我在本地运行我的 rspec 测试时,一切都通过了,但是当我在 Circle CI 上运行它们时,我得到了 rspec 错误:Redis::CannotConnectError:
.
我最近为 SideKiq 添加了功能测试。它使用 Redis 和 Chrome 驱动程序。
我想我需要将 redis 构建添加到我的 cimg 中,但不知道该怎么做。
Rspec 测试结果
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'
CirclCI 的 config.yml
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
解决方案
在测试环境中,通常最好不要在 Redis 中排队作业。该文档包含有关如何在测试中配置 Sidekiq 的信息。
推荐阅读
- javascript - 承诺获取数据
- java - API 方法可以返回不同的类型,我如何定义返回类型?
- avplayer - 保存在临时文件夹中的视频在模拟器上的 AVPlayer 中有效,但在真实设备上无效
- variables - 如何在modelica中更新变量以及模拟时间?
- java - JPA/Hibernate:如何扫描 Persistence.xml 中的特定包而不是给出单个实体名称?
- sql - 在 BigQuery 中多次乘以时间戳数据
- reactjs - 通过 Material UI ButtonGroup 增加和减少按钮
- excel - 如何在两个不同的工作表列之间找到匹配项并进行 vlookup 以提取数据
- c# - 使用 Visual Studio 使用 Home Grown Nuget 包的正确方法
- wordpress - 如果转发器位于组中,如何更新转发器字段