Skip to content

Commit

Permalink
Fix for Http timeout bypass for Sync Client
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Oct 18, 2023
1 parent ba34994 commit ec8a070
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Fixed
- Python 3.7 support, by @HardNorth
- Launch UUID attribute for AIO clients, by @HardNorth
- Http timeout bypass for Sync Client, by @HardNorth

## [5.5.2]
### Fixed
Expand Down
36 changes: 17 additions & 19 deletions reportportal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ def start_launch(self,
rerun=rerun,
rerun_of=rerun_of
).payload
response = HttpRequest(self.session.post, url=url, json=request_payload,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.post, url=url, json=request_payload, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
if not response:
return

Expand Down Expand Up @@ -614,10 +614,8 @@ def start_test_item(self,
test_case_id=test_case_id
).payload

response = HttpRequest(self.session.post,
url=url,
json=request_payload,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.post, url=url, json=request_payload, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
if not response:
return
item_id = response.id
Expand Down Expand Up @@ -665,8 +663,8 @@ def finish_test_item(self,
issue=issue,
retry=retry
).payload
response = HttpRequest(self.session.put, url=url, json=request_payload,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.put, url=url, json=request_payload, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
if not response:
return
self._remove_current_item()
Expand Down Expand Up @@ -699,8 +697,8 @@ def finish_launch(self,
description=kwargs.get('description')
).payload
response = HttpRequest(self.session.put, url=url, json=request_payload,
verify_ssl=self.verify_ssl,
name='Finish Launch').make()
verify_ssl=self.verify_ssl, name='Finish Launch',
http_timeout=self.http_timeout).make()
if not response:
return
logger.debug('finish_launch - ID: %s', self.launch_uuid)
Expand All @@ -726,8 +724,8 @@ def update_test_item(self, item_uuid: str, attributes: Optional[Union[list, dict
}
item_id = self.get_item_id_by_uuid(item_uuid)
url = uri_join(self.base_url_v1, 'item', item_id, 'update')
response = HttpRequest(self.session.put, url=url, json=data,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.put, url=url, json=data, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
if not response:
return
logger.debug('update_test_item - Item: %s', item_id)
Expand All @@ -737,7 +735,7 @@ def _log(self, batch: Optional[List[RPRequestLog]]) -> Optional[Tuple[str, ...]]
if batch:
url = uri_join(self.base_url_v2, 'log')
response = HttpRequest(self.session.post, url, files=RPLogBatch(batch).payload,
verify_ssl=self.verify_ssl).make()
verify_ssl=self.verify_ssl, http_timeout=self.http_timeout).make()
return response.messages

def log(self,
Expand Down Expand Up @@ -772,8 +770,8 @@ def get_item_id_by_uuid(self, item_uuid: str) -> Optional[str]:
:return: Test Item ID.
"""
url = uri_join(self.base_url_v1, 'item', 'uuid', item_uuid)
response = HttpRequest(self.session.get, url=url,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.get, url=url, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
return response.id if response else None

def get_launch_info(self) -> Optional[dict]:
Expand All @@ -785,8 +783,8 @@ def get_launch_info(self) -> Optional[dict]:
return {}
url = uri_join(self.base_url_v1, 'launch', 'uuid', self.launch_uuid)
logger.debug('get_launch_info - ID: %s', self.launch_uuid)
response = HttpRequest(self.session.get, url=url,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.get, url=url, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
if not response:
return
launch_info = None
Expand Down Expand Up @@ -835,8 +833,8 @@ def get_project_settings(self) -> Optional[dict]:
:return: Settings response in Dictionary.
"""
url = uri_join(self.base_url_v1, 'settings')
response = HttpRequest(self.session.get, url=url,
verify_ssl=self.verify_ssl).make()
response = HttpRequest(self.session.get, url=url, verify_ssl=self.verify_ssl,
http_timeout=self.http_timeout).make()
return response.json if response else None

def _add_current_item(self, item: str) -> None:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,35 @@ def test_attribute_truncation(rp_client: RPClient, method, call_method, argument
assert 'attributes' in kwargs['json']
assert kwargs['json']['attributes']
assert len(kwargs['json']['attributes'][0]['value']) == 128


@pytest.mark.parametrize(
'method, call_method, arguments',
[
('start_launch', 'post', ['Test Launch', timestamp()]),
('start_test_item', 'post', ['Test Item', timestamp(), 'SUITE']),
('finish_test_item', 'put', ['test_item_uuid', timestamp()]),
('finish_launch', 'put', [timestamp()]),
('update_test_item', 'put', ['test_item_uuid']),
('get_launch_info', 'get', []),
('get_project_settings', 'get', []),
('get_item_id_by_uuid', 'get', ['test_item_uuid']),
('log', 'post', [timestamp(), 'Test Message']),
]
)
def test_http_timeout_bypass(method, call_method, arguments):
http_timeout = (35.1, 33.3)
rp_client = RPClient('http://endpoint', 'project', 'api_key',
http_timeout=http_timeout, log_batch_size=1)
session: mock.Mock = mock.Mock()
rp_client.session = session
rp_client._skip_analytics = True

if method != 'start_launch':
rp_client._RPClient__launch_uuid = 'test_launch_id'

getattr(rp_client, method)(*arguments)
getattr(session, call_method).assert_called_once()
kwargs = getattr(session, call_method).call_args_list[0][1]
assert 'timeout' in kwargs
assert kwargs['timeout'] == http_timeout

0 comments on commit ec8a070

Please sign in to comment.