summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-06-29 22:14:06 +0000
committerStan Hu <stanhu@gmail.com>2016-06-29 22:14:06 +0000
commitf7eceed64483ecc831156d2ab2541a6793e92868 (patch)
tree8b2bff9591279de1c89289f85b03b91a09254a16 /spec/lib
parent65187efa5c7202e8b6429edfd17ad844cd584a32 (diff)
parentd10642a4b86d91faf7a3ffa508b4e8067213b14c (diff)
downloadgitlab-ce-f7eceed64483ecc831156d2ab2541a6793e92868.tar.gz
Merge branch 'handle-redis-not-there' into 'master'
Fix database migrations when Redis is not running If Redis were not running or USE_DB were set to false, the application settings retrieval would fail completely. This change only attempts to use the cache if the system actually wants to connect to the DB and rescues any failures in talking to Redis. Closes #17557 See merge request !4924
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/current_settings_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb
new file mode 100644
index 00000000000..004341ffd02
--- /dev/null
+++ b/spec/lib/gitlab/current_settings_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Gitlab::CurrentSettings do
+ describe '#current_application_settings' do
+ it 'attempts to use cached values first' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
+ expect(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults)
+ expect(ApplicationSetting).not_to receive(:last)
+
+ expect(current_application_settings).to be_a(ApplicationSetting)
+ end
+
+ it 'does not attempt to connect to DB or Redis' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(false)
+ expect(ApplicationSetting).not_to receive(:current)
+ expect(ApplicationSetting).not_to receive(:last)
+
+ expect(current_application_settings).to eq fake_application_settings
+ end
+
+ it 'falls back to DB if Redis returns an empty value' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
+ expect(ApplicationSetting).to receive(:last).and_call_original
+
+ expect(current_application_settings).to be_a(ApplicationSetting)
+ end
+
+ it 'falls back to DB if Redis fails' do
+ allow_any_instance_of(Gitlab::CurrentSettings).to receive(:connect_to_db?).and_return(true)
+ expect(ApplicationSetting).to receive(:current).and_raise(::Redis::BaseError)
+ expect(ApplicationSetting).to receive(:last).and_call_original
+
+ expect(current_application_settings).to be_a(ApplicationSetting)
+ end
+ end
+end