Commit e59e18c5 authored by Nick Thomas's avatar Nick Thomas

Use the configured redis DB in specs that run workhorse

Rails configures the redis DB in the URL, while workhorse uses a
separate config entry. Handle this in the specs in preparation for
running them against redis db 1 instead of redis db 0
parent ae1cc3a5
......@@ -8,6 +8,10 @@ require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/string/inflections'
# Explicitly load Redis::Store::Factory so we can read Redis configuration in
# TestEnv
require 'redis/store/factory'
module Gitlab
module Redis
class Wrapper
......
......@@ -32,7 +32,7 @@ module Gitlab
extend Gitlab::SetupHelper
class << self
def configuration_toml(dir, _, _)
config = { redis: { URL: redis_url } }
config = { redis: { URL: redis_url, DB: redis_db } }
TomlRB.dump(config)
end
......@@ -41,6 +41,10 @@ module Gitlab
Gitlab::Redis::SharedState.url
end
def redis_db
Gitlab::Redis::SharedState.params.fetch(:db, 0)
end
def get_config_path(dir, _)
File.join(dir, 'config_path')
end
......
......@@ -22,4 +22,28 @@ RSpec.describe Gitlab::SetupHelper::Workhorse do
end
end
end
describe '.redis_url' do
it 'matches the SharedState URL' do
expect(Gitlab::Redis::SharedState).to receive(:url).and_return('foo')
expect(described_class.redis_url).to eq('foo')
end
end
describe '.redis_db' do
subject { described_class.redis_db }
it 'matches the SharedState DB' do
expect(Gitlab::Redis::SharedState).to receive(:params).and_return(db: 1)
is_expected.to eq(1)
end
it 'defaults to 0 if unspecified' do
expect(Gitlab::Redis::SharedState).to receive(:params).and_return({})
is_expected.to eq(0)
end
end
end
......@@ -263,8 +263,13 @@ module TestEnv
# Feature specs are run through Workhorse
def setup_workhorse
# Always rebuild the config file
if skip_compile_workhorse?
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil)
return
end
start = Time.now
return if skip_compile_workhorse?
FileUtils.rm_rf(workhorse_dir)
Gitlab::SetupHelper::Workhorse.compile_into(workhorse_dir)
......@@ -305,12 +310,6 @@ module TestEnv
config_path = Gitlab::SetupHelper::Workhorse.get_config_path(workhorse_dir, {})
# This should be set up in setup_workhorse, but since
# component_needs_update? only checks that versions are consistent,
# we need to ensure the config file exists. This line can be removed
# later after a new Workhorse version is updated.
Gitlab::SetupHelper::Workhorse.create_configuration(workhorse_dir, nil) unless File.exist?(config_path)
workhorse_pid = spawn(
{ 'PATH' => "#{ENV['PATH']}:#{workhorse_dir}" },
File.join(workhorse_dir, 'gitlab-workhorse'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment