diff --git a/files/gitlab-ctl-commands/lib/postgresql/decomposition_migration.rb b/files/gitlab-ctl-commands/lib/postgresql/decomposition_migration.rb index 79e3ff74a8267d8ae8d03c6b98d4c1d2d0d383dd_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy9saWIvcG9zdGdyZXNxbC9kZWNvbXBvc2l0aW9uX21pZ3JhdGlvbi5yYg==..c765aa15b3a6f5d2b8f09fb21697e78bbba119e6_ZmlsZXMvZ2l0bGFiLWN0bC1jb21tYW5kcy9saWIvcG9zdGdyZXNxbC9kZWNvbXBvc2l0aW9uX21pZ3JhdGlvbi5yYg== 100644 --- a/files/gitlab-ctl-commands/lib/postgresql/decomposition_migration.rb +++ b/files/gitlab-ctl-commands/lib/postgresql/decomposition_migration.rb @@ -96,7 +96,7 @@ def run_migration puts "Copying data to new database..." - run_command("gitlab-rake gitlab:db:decomposition:migrate") + run_command("gitlab-rake gitlab:db:decomposition:migrate", timeout: 84_600) end def post_migrate @@ -109,8 +109,8 @@ run_command("gitlab-ctl restart") end - def run_command(cmd) - GitlabCtl::Util.run_command(cmd).tap do |status| + def run_command(cmd, timeout: nil) + GitlabCtl::Util.run_command(cmd, timeout: timeout).tap do |status| if status.error? enable_background_migrations unless background_migrations_initally_disabled? diff --git a/spec/chef/gitlab-ctl-commands/lib/postgresql/decomposition_migration_spec.rb b/spec/chef/gitlab-ctl-commands/lib/postgresql/decomposition_migration_spec.rb index 79e3ff74a8267d8ae8d03c6b98d4c1d2d0d383dd_c3BlYy9jaGVmL2dpdGxhYi1jdGwtY29tbWFuZHMvbGliL3Bvc3RncmVzcWwvZGVjb21wb3NpdGlvbl9taWdyYXRpb25fc3BlYy5yYg==..c765aa15b3a6f5d2b8f09fb21697e78bbba119e6_c3BlYy9jaGVmL2dpdGxhYi1jdGwtY29tbWFuZHMvbGliL3Bvc3RncmVzcWwvZGVjb21wb3NpdGlvbl9taWdyYXRpb25fc3BlYy5yYg== 100644 --- a/spec/chef/gitlab-ctl-commands/lib/postgresql/decomposition_migration_spec.rb +++ b/spec/chef/gitlab-ctl-commands/lib/postgresql/decomposition_migration_spec.rb @@ -45,5 +45,5 @@ context 'when external command fails' do before do - allow(GitlabCtl::Util).to receive(:run_command).and_return(command_fail) + allow(GitlabCtl::Util).to receive(:run_command).with(any_args).and_return(command_fail) allow(GitlabCtl::Util).to receive(:run_command).with( @@ -49,8 +49,9 @@ allow(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-rails runner \"Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)\"\n" + "gitlab-rails runner \"Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)\"\n", + timeout: nil ).and_return(command_ok) end context 'and background migrations are enabled before starting this script' do it 'enables background migrations and then exits' do expect(GitlabCtl::Util).to receive(:run_command).with( @@ -51,10 +52,11 @@ ).and_return(command_ok) end context 'and background migrations are enabled before starting this script' do it 'enables background migrations and then exits' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-rails runner \"Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)\"\n" + "gitlab-rails runner \"Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)\"\n", + timeout: nil ).and_return(command_ok) expect { instance.migrate! }.to raise_error(SystemExit) @@ -76,9 +78,9 @@ context 'runs commands needed for migration to decomposed setup' do before do - allow(GitlabCtl::Util).to receive(:run_command).and_return(command_ok) + allow(GitlabCtl::Util).to receive(:run_command).with(any_args).and_return(command_ok) end context 'and background migrations are enabled before starting this script' do it 'disables background migrations' do expect(GitlabCtl::Util).to receive(:run_command).with( @@ -80,9 +82,10 @@ end context 'and background migrations are enabled before starting this script' do it 'disables background migrations' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-rails runner \"Feature.disable(:execute_background_migrations) && Feature.disable(:execute_batched_migrations_on_schedule)\"\n" + "gitlab-rails runner \"Feature.disable(:execute_background_migrations) && Feature.disable(:execute_batched_migrations_on_schedule)\"\n", + timeout: nil ).and_return(command_ok) instance.migrate! @@ -103,11 +106,12 @@ it 'stops Gitlab except for PostgreSQL' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-ctl stop && gitlab-ctl start postgresql" - ).and_return(command_ok) + "gitlab-ctl stop && gitlab-ctl start postgresql", + timeout: nil + ).and_return(command_ok).once instance.migrate! end it 'calls the migration rake task' do expect(GitlabCtl::Util).to receive(:run_command).with( @@ -108,14 +112,15 @@ instance.migrate! end it 'calls the migration rake task' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-rake gitlab:db:decomposition:migrate" - ).and_return(command_ok) + "gitlab-rake gitlab:db:decomposition:migrate", + timeout: 84_600 + ).and_return(command_ok).once instance.migrate! end it 'runs the reconfigure task' do expect(GitlabCtl::Util).to receive(:run_command).with( @@ -116,14 +121,15 @@ instance.migrate! end it 'runs the reconfigure task' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-ctl reconfigure" - ).and_return(command_ok) + "gitlab-ctl reconfigure", + timeout: nil + ).and_return(command_ok).once instance.migrate! end it 'enables write locks' do expect(GitlabCtl::Util).to receive(:run_command).with( @@ -124,14 +130,15 @@ instance.migrate! end it 'enables write locks' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-rake gitlab:db:lock_writes" - ).and_return(command_ok) + "gitlab-rake gitlab:db:lock_writes", + timeout: nil + ).and_return(command_ok).once instance.migrate! end it 'restarts GitLab' do expect(GitlabCtl::Util).to receive(:run_command).with( @@ -132,11 +139,12 @@ instance.migrate! end it 'restarts GitLab' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-ctl restart" - ).and_return(command_ok) + "gitlab-ctl restart", + timeout: nil + ).and_return(command_ok).once instance.migrate! end @@ -144,8 +152,9 @@ context 'and background migrations are enabled before starting this script' do it 'enables background migrations' do expect(GitlabCtl::Util).to receive(:run_command).with( - "gitlab-rails runner \"Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)\"\n" - ).and_return(command_ok) + "gitlab-rails runner \"Feature.enable(:execute_background_migrations) && Feature.enable(:execute_batched_migrations_on_schedule)\"\n", + timeout: nil + ).and_return(command_ok).once instance.migrate! end