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/workers/database/monitor_locked_tables_worker_spec.rb')
-rw-r--r--spec/workers/database/monitor_locked_tables_worker_spec.rb55
1 files changed, 54 insertions, 1 deletions
diff --git a/spec/workers/database/monitor_locked_tables_worker_spec.rb b/spec/workers/database/monitor_locked_tables_worker_spec.rb
index 47475a0ad4a..7e900259265 100644
--- a/spec/workers/database/monitor_locked_tables_worker_spec.rb
+++ b/spec/workers/database/monitor_locked_tables_worker_spec.rb
@@ -19,6 +19,10 @@ RSpec.describe Database::MonitorLockedTablesWorker, feature_category: :cell do
end
context 'when running in decomposed database' do
+ before do
+ skip_if_shared_database(:ci)
+ end
+
context 'when the feature flag is disabled' do
before do
stub_feature_flags(monitor_database_locked_tables: false)
@@ -32,7 +36,6 @@ RSpec.describe Database::MonitorLockedTablesWorker, feature_category: :cell do
context 'when the feature flag is enabled' do
before do
- skip_if_shared_database(:ci)
stub_feature_flags(monitor_database_locked_tables: true)
allow(Gitlab::Database::TablesLocker).to receive(:new).and_return(tables_locker)
end
@@ -73,6 +76,56 @@ RSpec.describe Database::MonitorLockedTablesWorker, feature_category: :cell do
worker.perform
end
+
+ context 'with automatically locking the unlocked tables' do
+ context 'when there are no tables to be locked' do
+ before do
+ stub_feature_flags(lock_tables_in_monitoring: true)
+ allow(tables_locker).to receive(:lock_writes).and_return([])
+ end
+
+ it 'does not call the Database::LockTablesWorker' do
+ expect(Database::LockTablesWorker).not_to receive(:perform_async)
+ end
+ end
+
+ context 'when there are tables to be locked' do
+ before do
+ lock_writes_results = [
+ { table: 'users', database: 'ci', action: 'needs_lock' },
+ { table: 'projects', database: 'ci', action: 'needs_lock' },
+ { table: 'ci_builds', database: 'main', action: 'needs_lock' },
+ { table: 'ci_pipelines', database: 'main', action: 'skipped' }
+ ]
+ allow(tables_locker).to receive(:lock_writes).and_return(lock_writes_results)
+ end
+
+ context 'when feature flag lock_tables_in_monitoring is enabled' do
+ before do
+ stub_feature_flags(lock_tables_in_monitoring: true)
+ end
+
+ it 'locks the tables that need to be locked' do
+ expect(Database::LockTablesWorker).to receive(:perform_async).once.with('ci', %w[users projects])
+ expect(Database::LockTablesWorker).to receive(:perform_async).once.with('main', %w[ci_builds])
+
+ worker.perform
+ end
+ end
+
+ context 'when feature flag lock_tables_in_monitoring is disabled' do
+ before do
+ stub_feature_flags(lock_tables_in_monitoring: false)
+ end
+
+ it 'does not lock the tables that need to be locked' do
+ expect(Database::LockTablesWorker).not_to receive(:perform_async)
+
+ worker.perform
+ end
+ end
+ end
+ end
end
end
end