即使需要“sidekiq/testing”,Sidekiq 也尝试连接到 Redis

Sidekiq trying to connect to Redis even if 'sidekiq/testing' is required

提问人:sheva 提问时间:9/4/2023 更新时间:9/4/2023 访问量:93

问:

Ruby 版本:3.1.3 Rails 版本:7.0.4 Sidekiq / Pro / Enterprise 版本:标准版

sidekiq.rb 初始值设定项

# frozen_string_literal: true
require "sidekiq"
require "sidekiq-status"

redis_config = {
  url: "#{ENV["REDIS_URL"]}/#{REDIS_SIDEKIQ_DB}"
}

Sidekiq.configure_client do |config|
  config.redis = redis_config

  Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes.to_i
end

Sidekiq.configure_server do |config|
  config.redis = redis_config

  Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes.to_i
  Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes.to_i
end

spec_helper.rb

...
 require 'sidekiq-status/testing/inline'

  config.before(:each) do
    Sidekiq::Worker.clear_all
  end

my_file_spec.rb

require 'rails_helper'
RSpec.describe ExpirationCartJob, type: :job, focus: true do
  it { should be_retryable(false) }

  it { should respond_to(:perform) }
  it "should be able to enqueue a job" do
    expect { described_class.perform_async }.to enqueue_sidekiq_job
  end
end

完全回溯

2023-08-24T16:36:54.153Z pid=80056 tid=1kx0 INFO: Sidekiq 7.1.2 connecting to Redis with options {:size=>10, :pool_name=>"internal", :url=>"/2"}                        |  ETA: 00:00:01

  1) ExpirationCartJob should be able to enqueue a job
     Failure/Error: expect { described_class.perform_async }.to enqueue_sidekiq_job

     ArgumentError:
       Invalid URL: "/2"
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/redis-client-0.16.0/lib/redis_client/url_config.rb:16:in `initialize'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/redis-client-0.16.0/lib/redis_client/config.rb:165:in `new'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/redis-client-0.16.0/lib/redis_client/config.rb:165:in `initialize'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/redis-client-0.16.0/lib/redis_client.rb:144:in `new'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/redis-client-0.16.0/lib/redis_client.rb:144:in `config'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/redis_client_adapter.rb:52:in `initialize'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/redis_connection.rb:21:in `new'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/redis_connection.rb:21:in `create'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/config.rb:140:in `new_redis_pool'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/config.rb:134:in `local_redis_pool'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/config.rb:128:in `redis_pool'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/job.rb:368:in `build_client'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/job.rb:361:in `client_push'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/job.rb:198:in `perform_async'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/sidekiq-7.1.2/lib/sidekiq/job.rb:286:in `perform_async'
     # ./spec/sidekiq/expiration_cart_job_spec.rb:7:in `block (3 levels) in <main>'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-sidekiq-4.0.1/lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb:23:in `matches?'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:51:in `block in handle_matcher'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:27:in `with_matcher'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-expectations-3.12.3/lib/rspec/expectations/expectation_target.rb:65:in `to'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-expectations-3.12.3/lib/rspec/expectations/expectation_target.rb:139:in `to'
     # ./spec/sidekiq/expiration_cart_job_spec.rb:7:in `block (2 levels) in <main>'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:263:in `instance_exec'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:263:in `block in run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:486:in `block in run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:352:in `call'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-rails-6.0.3/lib/rspec/rails/adapters.rb:75:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:457:in `instance_exec'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:457:in `instance_exec'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:390:in `execute_with'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:352:in `call'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:457:in `instance_exec'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:457:in `instance_exec'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:390:in `execute_with'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:352:in `call'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:486:in `run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:259:in `run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:646:in `block in run_examples'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:642:in `map'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:642:in `run_examples'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:607:in `run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:121:in `map'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/configuration.rb:2070:in `with_suite_hooks'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:116:in `block in run_specs'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/reporter.rb:74:in `report'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:115:in `run_specs'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:89:in `run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:71:in `run'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:45:in `invoke'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/gems/rspec-core-3.12.2/exe/rspec:4:in `<top (required)>'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/bin/rspec:25:in `load'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/bin/rspec:25:in `<main>'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/bin/ruby_executable_hooks:22:in `eval'
     # /Users/mateo/.rvm/gems/ruby-3.1.3/bin/ruby_executable_hooks:22:in `<main>'

我已经在另一个项目中以相同的方式进行了设置,并且效果很好。但是在这个中,由于某种原因,它试图连接到 Redis,而文档也说它不应该。

根据文档,需要“sidekiq/testing”应该避免调用 Redis。

Ruby-on-Rails Sidekiq (英语

评论


答: 暂无答案