Skip to content

Commit

Permalink
environment sync, fixes #5932
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed May 25, 2023
1 parent e813661 commit 94f9003
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

[Sidekiq Changes](https://github.com/sidekiq/sidekiq/blob/main/Changes.md) | [Sidekiq Pro Changes](https://github.com/sidekiq/sidekiq/blob/main/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/sidekiq/sidekiq/blob/main/Ent-Changes.md)

HEAD
7.1.1
----------

- Support multiple CurrentAttributes [#5904]
- Speed up latency fetch with large queues on Redis <7 [#5910]
- Allow a larger default client pool [#5886]
- Ensure Sidekiq.options[:environment] == RAILS_ENV [#5932]

7.1.0
----------
Expand Down Expand Up @@ -108,6 +109,11 @@ end
- Job Execution metrics!!!
- See `docs/7.0-Upgrade.md` for release notes

6.5.9
----------

- Ensure Sidekiq.options[:environment] == RAILS_ENV [#5932]

6.5.8
----------

Expand Down
1 change: 1 addition & 0 deletions lib/sidekiq/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def set_environment(cli_env)
# Both Sinatra 2.0+ and Sidekiq support this term.
# RAILS_ENV and RACK_ENV are there for legacy support.
@environment = cli_env || ENV["APP_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
config[:environment] = @environment
end

def symbolize_keys_deep!(hash)
Expand Down
24 changes: 13 additions & 11 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

describe Sidekiq::CLI do
before do
ENV["RAILS_ENV"] = ENV["RACK_ENV"] = ENV["APP_ENV"] = nil
@logdev = StringIO.new
@config = reset!
@config.logger = Logger.new(@logdev)
Expand Down Expand Up @@ -133,14 +134,24 @@ def capsules
end
end

describe "environmental" do
it "handles RAILS_ENV" do
ENV["RAILS_ENV"] = "xyzzy"
@cli.parse(%w[sidekiq -C ./test/config.yml])
assert_equal "xyzzy", config[:environment]
ensure
ENV.delete "RAILS_ENV"
end
end

describe "config file" do
it "accepts with -C" do
@cli.parse(%w[sidekiq -C ./test/config.yml])

assert_equal "./test/config.yml", config[:config_file]
refute config[:verbose]
assert_equal "./test/fake_env.rb", config[:require]
assert_nil config[:environment]
assert_equal "development", config[:environment]
assert_equal 50, concurrency
assert_equal 2, queues.count { |q| q == "very_often" }
assert_equal 1, queues.count { |q| q == "seldom" }
Expand All @@ -152,7 +163,7 @@ def capsules
assert_equal "./test/cfg/config_string.yml", config[:config_file]
refute config[:verbose]
assert_equal "./test/fake_env.rb", config[:require]
assert_nil config[:environment]
assert_equal "development", config[:environment]
assert_equal 50, concurrency
assert_equal 2, queues.count { |q| q == "very_often" }
assert_equal 1, queues.count { |q| q == "seldom" }
Expand Down Expand Up @@ -377,15 +388,6 @@ def capsules
end
end

it "prints rails info" do
@cli.stub(:environment, "production") do
@cli.stub(:launch, nil) do
@cli.run
end
assert_includes @logdev.string, "Booted Rails #{::Rails.version} application in production environment"
end
end

describe "checking maxmemory policy" do
it "warns if the policy is not noeviction" do
redis_info = {"maxmemory_policy" => "allkeys-lru", "redis_version" => "6.2.1"}
Expand Down

0 comments on commit 94f9003

Please sign in to comment.