Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/database/reindexing_spec.rb')
-rw-r--r--spec/lib/gitlab/database/reindexing_spec.rb29
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