summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database
diff options
context:
space:
mode:
authorGabriel Mazetto <brodock@gmail.com>2018-08-11 01:45:46 +0200
committerGabriel Mazetto <brodock@gmail.com>2018-08-11 04:15:59 +0200
commitf21e655b61725b972ae80d584a66d6deb53a337d (patch)
treef9fb191d364e30119eb7c02f65e4eef12936a232 /spec/lib/gitlab/database
parentf6d47d0dee0cbbb49f778de9d196c3dae0dbce7f (diff)
downloadgitlab-ce-f21e655b61725b972ae80d584a66d6deb53a337d.tar.gz
disable_statement_timeout doesn't require any argument anymore
it will decide the method for disable statement_timeout upon per transaction or per session, based on how it's called. When calling with a block, block will be executed and it will use session based statement_timeout, otherwise will default to existing behavior.
Diffstat (limited to 'spec/lib/gitlab/database')
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb75
1 files changed, 32 insertions, 43 deletions
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb
index 28a03e6f6f6..4e83b27e4a5 100644
--- a/spec/lib/gitlab/database/migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers_spec.rb
@@ -296,52 +296,43 @@ describe Gitlab::Database::MigrationHelpers do
describe '#disable_statement_timeout' do
context 'using PostgreSQL' do
- context 'with transaction: true' do
- it 'disables statement timeouts to current transaction only' do
- expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
-
- expect(model).to receive(:execute).with('SET LOCAL statement_timeout TO 0')
+ it 'disables statement timeouts to current transaction only' do
+ expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
- model.disable_statement_timeout
- end
+ expect(model).to receive(:execute).with('SET LOCAL statement_timeout TO 0')
- # this specs runs without an enclosing transaction (:delete truncation method for db_cleaner)
- context 'with real environment', :postgresql, :delete do
- before do
- model.execute("SET statement_timeout TO '20000'")
- end
+ model.disable_statement_timeout
+ end
- after do
- model.execute('RESET ALL')
- end
+ # this specs runs without an enclosing transaction (:delete truncation method for db_cleaner)
+ context 'with real environment', :postgresql, :delete do
+ before do
+ model.execute("SET statement_timeout TO '20000'")
+ end
- it 'defines statement to 0 only for current transaction' do
- expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('20s')
+ after do
+ model.execute('RESET ALL')
+ end
- model.connection.transaction do
- model.disable_statement_timeout
- expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('0')
- end
+ it 'defines statement to 0 only for current transaction' do
+ expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('20s')
- expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('20s')
+ model.connection.transaction do
+ model.disable_statement_timeout
+ expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('0')
end
+
+ expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('20s')
end
end
- context 'with transaction: false' do
- it 'disables statement timeouts on session level' do
+ context 'when passing a blocks' do
+ it 'disables statement timeouts on session level and executes the block' do
expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
expect(model).to receive(:execute).with('SET statement_timeout TO 0')
expect(model).to receive(:execute).with('RESET ALL')
- model.disable_statement_timeout(transaction: false) do
- # no-op
- end
- end
-
- it 'raises error when no block is given' do
- expect(Gitlab::Database).to receive(:postgresql?).and_return(true)
- expect { model.disable_statement_timeout(transaction: false) }.to raise_error(ArgumentError)
+ expect { |block| model.disable_statement_timeout(&block) }.to yield_control
end
# this specs runs without an enclosing transaction (:delete truncation method for db_cleaner)
@@ -354,10 +345,10 @@ describe Gitlab::Database::MigrationHelpers do
model.execute('RESET ALL')
end
- it 'defines statement to 0 for any code run inside block' do
+ it 'defines statement to 0 for any code run inside the block' do
expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('20s')
- model.disable_statement_timeout(transaction: false) do
+ model.disable_statement_timeout do
model.connection.transaction do
expect(model.execute('SHOW statement_timeout').first['statement_timeout']).to eq('0')
end
@@ -370,23 +361,21 @@ describe Gitlab::Database::MigrationHelpers do
end
context 'using MySQL' do
- context 'with transaction: true' do
- it 'does nothing' do
- expect(Gitlab::Database).to receive(:postgresql?).and_return(false)
+ it 'does nothing' do
+ expect(Gitlab::Database).to receive(:postgresql?).and_return(false)
- expect(model).not_to receive(:execute)
+ expect(model).not_to receive(:execute)
- model.disable_statement_timeout
- end
+ model.disable_statement_timeout
end
- context 'with transaction: false' do
- it 'executes yielded code' do
+ context 'when passing a blocks' do
+ it 'executes the block of code' do
expect(Gitlab::Database).to receive(:postgresql?).and_return(false)
expect(model).not_to receive(:execute)
- expect { |block| model.disable_statement_timeout(transaction: false, &block) }.to yield_control
+ expect { |block| model.disable_statement_timeout(&block) }.to yield_control
end
end
end