blob: 9b4be30b1303b21472edb154c67d11fcb0f15fa5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
require 'spec_helper'
require_relative '../../../lib/gitaly_server/sentry_interceptor.rb'
describe GitalyServer::SentryInterceptor do
describe 'handling exceptions' do
let(:meth) { GitalyServer::OperationsService.instance_method(:user_create_branch) }
let(:ex) { ArgumentError.new("unknown encoding") }
let(:call) { nil }
subject do
described_class.new.server_streamer(call: call, method: meth) { raise ex }
end
context 'Sentry is disabled' do
it 're-raises the exception' do
expect { subject }.to raise_error(ex)
end
it 'sends nothing to Sentry' do
expect(Raven).not_to receive(:capture_exception)
begin
subject
rescue
nil
end
end
end
context 'Sentry is enabled' do
before do
allow(GitalyServer::Sentry).to receive(:enabled?).and_return(true)
end
let(:call_metadata) do
{
'user-agent' => 'grpc-go/1.9.1',
'gitaly-storage-path' => '/home/git/repositories',
'gitaly-repo-path' => '/home/git/repositories/gitlab-org/gitaly.git',
'gitaly-gl-repository' => 'project-52',
'gitaly-repo-alt-dirs' => ''
}
end
let(:call) { double(metadata: call_metadata) }
let(:expected_tags) do
call_metadata.merge(
'system' => 'gitaly-ruby',
'gitaly-ruby.method' => 'GitalyServer::OperationsService#user_create_branch'
)
end
it 're-raises the exception' do
expect { subject }.to raise_error(ex)
end
it 'sets Sentry tags' do
expect(Raven).to receive(:tags_context).with(hash_including(expected_tags))
begin
subject
rescue
nil
end
end
context 'when expcetion is normal' do
it 'sends the exception to Sentry' do
expect(Raven).to receive(:capture_exception).with(
ex,
fingerprint: ['gitaly-ruby', 'GitalyServer::OperationsService#user_create_branch', 'unknown encoding']
)
begin
subject
rescue
nil
end
end
end
end
end
end
|