diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/database/reindexing_spec.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/database/reindexing_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database/reindexing_spec.rb | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/spec/lib/gitlab/database/reindexing_spec.rb b/spec/lib/gitlab/database/reindexing_spec.rb index 8aff99544ca..550f9db2b5b 100644 --- a/spec/lib/gitlab/database/reindexing_spec.rb +++ b/spec/lib/gitlab/database/reindexing_spec.rb @@ -26,14 +26,31 @@ RSpec.describe Gitlab::Database::Reindexing do end end - describe '.candidate_indexes' do - subject { described_class.candidate_indexes } + describe '.cleanup_leftovers!' do + subject { described_class.cleanup_leftovers! } + + before do + ApplicationRecord.connection.execute(<<~SQL) + CREATE INDEX foobar_ccnew ON users (id); + CREATE INDEX foobar_ccnew1 ON users (id); + SQL + end - it 'retrieves regular indexes that are no left-overs from previous runs' do - result = double - expect(Gitlab::Database::PostgresIndex).to receive_message_chain('not_match.reindexing_support').with('\_ccnew[0-9]*$').with(no_args).and_return(result) + it 'drops both leftover indexes' do + expect_query("SET lock_timeout TO '60000ms'") + expect_query("DROP INDEX CONCURRENTLY IF EXISTS \"public\".\"foobar_ccnew\"") + expect_query("RESET idle_in_transaction_session_timeout; RESET lock_timeout") + expect_query("SET lock_timeout TO '60000ms'") + expect_query("DROP INDEX CONCURRENTLY IF EXISTS \"public\".\"foobar_ccnew1\"") + expect_query("RESET idle_in_transaction_session_timeout; RESET lock_timeout") - expect(subject).to eq(result) + subject + end + + def expect_query(sql) + expect(ApplicationRecord.connection).to receive(:execute).ordered.with(sql).and_wrap_original do |method, sql| + method.call(sql.sub(/CONCURRENTLY/, '')) + end end end end |