2
2
3
3
import pytest
4
4
5
+ from sentry .integrations .gitlab .constants import GITLAB_CLOUD_BASE_URL
5
6
from sentry .integrations .source_code_management .commit_context import (
6
7
CommitContextIntegration ,
7
8
SourceLineInfo ,
@@ -20,6 +21,7 @@ class MockCommitContextIntegration(CommitContextIntegration):
20
21
21
22
def __init__ (self ):
22
23
self .client = Mock ()
24
+ self .client .base_url = "https://example.com"
23
25
24
26
def get_client (self ):
25
27
return self .client
@@ -122,6 +124,58 @@ class MockGitlabIntegration(MockCommitContextIntegration):
122
124
assert_slo_metric (mock_record , EventLifecycleOutcome .HALTED )
123
125
assert_halt_metric (mock_record , ApiInvalidRequestError (text = "Invalid request" ))
124
126
127
+ @patch ("sentry.integrations.utils.metrics.EventLifecycle.record_event" )
128
+ def test_get_blame_for_files_retry_error (self , mock_record ):
129
+ """Test retry error for Gitlab Self-hosted records halt"""
130
+ from sentry .shared_integrations .exceptions import ApiRetryError
131
+
132
+ # Because this is Gitlab Self-hosted, this should be halt
133
+ class MockGitlabIntegration (MockCommitContextIntegration ):
134
+ integration_name = "gitlab"
135
+ base_url = "https://bufo-bot.gitlab.com"
136
+
137
+ def __init__ (self ):
138
+ super ().__init__ ()
139
+ self .client .base_url = self .base_url
140
+
141
+ self .integration = MockGitlabIntegration ()
142
+
143
+ self .integration .client .get_blame_for_files = Mock (
144
+ side_effect = ApiRetryError (text = "Host error" )
145
+ )
146
+
147
+ result = self .integration .get_blame_for_files ([self .source_line ], {})
148
+
149
+ assert result == []
150
+ assert_slo_metric (mock_record , EventLifecycleOutcome .HALTED )
151
+ assert_halt_metric (mock_record , ApiRetryError (text = "Host error" ))
152
+
153
+ @patch ("sentry.integrations.utils.metrics.EventLifecycle.record_event" )
154
+ def test_get_blame_for_files_retry_error_gitlab (self , mock_record ):
155
+ """Test retry error for GitLab saas records failure"""
156
+ from sentry .shared_integrations .exceptions import ApiRetryError
157
+
158
+ # Because this is Gitlab SAAS, this should be failure
159
+ class MockGitlabIntegration (MockCommitContextIntegration ):
160
+ integration_name = "gitlab"
161
+ base_url = GITLAB_CLOUD_BASE_URL
162
+
163
+ def __init__ (self ):
164
+ super ().__init__ ()
165
+ self .client .base_url = self .base_url
166
+
167
+ self .integration = MockGitlabIntegration ()
168
+
169
+ self .integration .client .get_blame_for_files = Mock (
170
+ side_effect = ApiRetryError (text = "Host error" )
171
+ )
172
+
173
+ with pytest .raises (ApiRetryError ):
174
+ self .integration .get_blame_for_files ([self .source_line ], {})
175
+
176
+ assert_slo_metric (mock_record , EventLifecycleOutcome .FAILURE )
177
+ assert_failure_metric (mock_record , ApiRetryError (text = "Host error" ))
178
+
125
179
@patch ("sentry.integrations.utils.metrics.EventLifecycle.record_event" )
126
180
def test_get_commit_context_all_frames (self , mock_record ):
127
181
"""Test get_commit_context_all_frames records correct lifecycle events"""
0 commit comments