diff options
author | Michael Kozono <mkozono@gmail.com> | 2018-06-11 11:51:53 -0700 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2018-07-24 21:21:13 -0700 |
commit | ffb0996cf4e9ccc329a04c817dcfe51534ca26f4 (patch) | |
tree | 7a3d28568b7bb37e60cbd81ed54f9f41c471807f | |
parent | 86295a705c62ad98de00efa3e1112a99d5f6bde7 (diff) | |
download | gitlab-ce-mk/fix-callback-canceling-in-namespace-move-dir.tar.gz |
Notify Sentry in productionmk/fix-callback-canceling-in-namespace-move-dir
-rw-r--r-- | app/models/concerns/storage/legacy_namespace.rb | 5 | ||||
-rw-r--r-- | spec/models/namespace_spec.rb | 31 |
2 files changed, 26 insertions, 10 deletions
diff --git a/app/models/concerns/storage/legacy_namespace.rb b/app/models/concerns/storage/legacy_namespace.rb index 203d2ea9a2b..ae6595320cb 100644 --- a/app/models/concerns/storage/legacy_namespace.rb +++ b/app/models/concerns/storage/legacy_namespace.rb @@ -34,8 +34,9 @@ module Storage begin send_update_instructions write_projects_repository_config - rescue - # Swallow exceptions + rescue => e + # Raise if development/test environment, else just notify Sentry + Gitlab::Sentry.track_exception(e, extra: { full_path_was: full_path_was, full_path: full_path, action: 'move_dir' }) end true # false would cancel later callbacks but not rollback diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 7b40fdb0af9..8ff16cbd7cc 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -205,17 +205,32 @@ describe Namespace do expect(gitlab_shell.exists?(project.repository_storage, "#{namespace.path}/#{project.path}.git")).to be_truthy end - it 'does not cancel later callbacks if #write_projects_repository_config raises an error' do - expect(namespace).to receive(:write_projects_repository_config).and_raise('some error') - expect(namespace).to receive(:move_dir).and_wrap_original do |m, *args| - move_dir_result = m.call(*args) + context 'when #write_projects_repository_config raises an error' do + context 'in test environment' do + it 'raises an exception' do + expect(namespace).to receive(:write_projects_repository_config).and_raise('foo') + + expect do + namespace.update(path: namespace.full_path + '_new') + end.to raise_error('foo') + end + end - expect(move_dir_result).to be_truthy # Must be truthy, or else later callbacks would be canceled + context 'in production environment' do + it 'does not cancel later callbacks' do + expect(namespace).to receive(:write_projects_repository_config).and_raise('foo') + expect(namespace).to receive(:move_dir).and_wrap_original do |m, *args| + move_dir_result = m.call(*args) - move_dir_result - end + expect(move_dir_result).to be_truthy # Must be truthy, or else later callbacks would be canceled - namespace.update_attributes(path: namespace.full_path + '_new') + move_dir_result + end + expect(Gitlab::Sentry).to receive(:should_raise?).and_return(false) # like prod + + namespace.update(path: namespace.full_path + '_new') + end + end end context 'with subgroups', :nested_groups do |