зеркало из https://github.com/github/octobox.git
Add config option for database timeout (#2126)
This commit is contained in:
Родитель
deb5d6c21c
Коммит
72d1253398
|
@ -5,6 +5,8 @@ default: &default
|
|||
password: <%= DatabaseConfig.password %>
|
||||
host: <%= DatabaseConfig.host %>
|
||||
port: <%= DatabaseConfig.port %>
|
||||
variables:
|
||||
statement_timeout: <%= DatabaseConfig.timeout %>
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
|
|
|
@ -91,6 +91,12 @@ module DatabaseConfig
|
|||
end.to_i
|
||||
end
|
||||
|
||||
def timeout
|
||||
database_url_or_fallback('timeout') do
|
||||
ENV.fetch("OCTOBOX_STATEMENT_TIMEOUT") { 10000 }.to_i
|
||||
end.to_i
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def database_url_or_fallback(var)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DatabaseConfigTest < ActiveSupport::TestCase
|
||||
DB_URL = "postgresql://user:password2@host.com:1234/database_name?pool=15&encoding=db_url_encoding"
|
||||
DB_URL = "postgresql://user:password2@host.com:1234/database_name?pool=15&encoding=db_url_encoding&timeout=1000"
|
||||
|
||||
test 'chooses the right DB' do
|
||||
if ENV['DATABASE']
|
||||
|
@ -112,6 +112,20 @@ class DatabaseConfigTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'timeout is specified properly' do
|
||||
set_env('DATABASE_URL', DB_URL) do
|
||||
assert_equal 1000, DatabaseConfig.timeout
|
||||
end
|
||||
|
||||
set_env('DATABASE', 'postgresql') do
|
||||
assert_equal 10000, DatabaseConfig.timeout
|
||||
end
|
||||
|
||||
set_env('OCTOBOX_STATEMENT_TIMEOUT', 5000) do |val|
|
||||
assert_equal val, DatabaseConfig.timeout
|
||||
end
|
||||
end
|
||||
|
||||
test 'port is specified properly' do
|
||||
set_env('DATABASE_URL', DB_URL) do
|
||||
assert_equal 1234, DatabaseConfig.port
|
||||
|
|
Загрузка…
Ссылка в новой задаче