File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 10
10
from functools import lru_cache
11
11
from typing import TYPE_CHECKING , Any
12
12
13
- from atlassian import Jira , errors
13
+ from atlassian import Jira
14
+ from atlassian import errors as atlassian_errors
15
+ from requests import exceptions as requests_exceptions
14
16
15
17
from jbi import Operation , environment
16
18
from jbi .models import ActionContext , BugzillaBug
27
29
28
30
JIRA_DESCRIPTION_CHAR_LIMIT = 32767
29
31
30
- instrumented_method = instrument (prefix = "jira" , exceptions = (errors .ApiError ,))
32
+ instrumented_method = instrument (
33
+ prefix = "jira" ,
34
+ exceptions = (
35
+ atlassian_errors .ApiError ,
36
+ requests_exceptions .RequestException ,
37
+ ),
38
+ )
31
39
32
40
33
41
class JiraClient (Jira ):
34
42
"""Adapted Atlassian Jira client that wraps methods in our instrumentation
35
43
decorator.
36
44
"""
37
45
46
+ get_server_info = instrumented_method (Jira .get_server_info )
47
+ get_permissions = instrumented_method (Jira .get_permissions )
48
+ get_project_components = instrumented_method (Jira .get_project_components )
49
+ projects = instrumented_method (Jira .projects )
38
50
update_issue_field = instrumented_method (Jira .update_issue_field )
39
51
set_issue_status = instrumented_method (Jira .set_issue_status )
40
52
issue_add_comment = instrumented_method (Jira .issue_add_comment )
Original file line number Diff line number Diff line change 2
2
3
3
import pytest
4
4
import responses
5
+ from requests .exceptions import ConnectionError
5
6
6
7
from jbi .environment import get_settings
7
8
from jbi .services import jira
@@ -89,3 +90,23 @@ def test_create_issue_with_components(mocked_responses, context_create_example):
89
90
posted_data = json .loads (mocked_responses .calls [- 1 ].request .body )
90
91
91
92
assert posted_data ["fields" ]["components" ] == [{"id" : "42" }]
93
+
94
+
95
+ @pytest .mark .no_mocked_jira
96
+ def test_jira_retries_failing_connections_in_health_check (
97
+ mocked_responses , actions_example
98
+ ):
99
+ url = f"{ get_settings ().jira_base_url } rest/api/2/serverInfo?doHealthCheck=True"
100
+
101
+ # When the request does not match any mocked URL, we also obtain
102
+ # a `ConnectionError`, but let's mock it explicitly.
103
+ mocked_responses .add (
104
+ responses .GET ,
105
+ url ,
106
+ body = ConnectionError (),
107
+ )
108
+
109
+ with pytest .raises (ConnectionError ):
110
+ jira .check_health (actions_example )
111
+
112
+ assert len (mocked_responses .calls ) == 4
You can’t perform that action at this time.
0 commit comments