Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #221

Merged
merged 270 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
270 commits
Select commit Hold shift + click to select a range
3fe68df
Async RPClient: WIP
HardNorth Sep 5, 2023
06976fa
Async RPClient: WIP
HardNorth Sep 5, 2023
fb1f403
Async RPClient: WIP
HardNorth Sep 5, 2023
02c933b
Async RPClient: WIP
HardNorth Sep 5, 2023
be2a0a3
Async RPClient: WIP
HardNorth Sep 5, 2023
089702c
Async RPClient: WIP
HardNorth Sep 5, 2023
9c05fdd
Async RPClient: WIP
HardNorth Sep 6, 2023
c5ebaff
Async RPClient: WIP
HardNorth Sep 6, 2023
2da024a
Async RPClient: WIP
HardNorth Sep 7, 2023
f117a2f
Fix typing
HardNorth Sep 7, 2023
3d41c9c
Fix loop run method reference
HardNorth Sep 7, 2023
a611524
Fix bugs
HardNorth Sep 7, 2023
a528086
Async RPClient: WIP
HardNorth Sep 7, 2023
7ea23a3
Async RPClient: WIP
HardNorth Sep 7, 2023
10f434f
Fix tests
HardNorth Sep 8, 2023
cc397d5
Async RPClient: WIP
HardNorth Sep 8, 2023
8dde2f6
Async RPClient: WIP
HardNorth Sep 8, 2023
6fb8344
Fix SSL Context for async_send_event function
HardNorth Sep 8, 2023
aca919c
Minor style changes
HardNorth Sep 8, 2023
a9d9f57
Add certify on connection configuration
HardNorth Sep 8, 2023
6891552
Fix payload conversion
HardNorth Sep 8, 2023
4d7d9fa
Revert worker update since it degrades performance
HardNorth Sep 8, 2023
af2306b
Add backward compatible methods
HardNorth Sep 8, 2023
4b3ffe6
Add task finishing wait
HardNorth Sep 8, 2023
69c5b1d
Correct launch finish logic
HardNorth Sep 8, 2023
73b37f5
Remove one TODO, add another one
HardNorth Sep 8, 2023
c89b566
Correct task wait sleep time
HardNorth Sep 8, 2023
04f957c
Add batched client implementation
HardNorth Sep 9, 2023
f54cf5c
Batched client update
HardNorth Sep 11, 2023
df5a9d0
Self Task type add
HardNorth Sep 12, 2023
868da81
Fix typing
HardNorth Sep 12, 2023
d6a4870
Refactoring
HardNorth Sep 12, 2023
a2111b7
Add batch logging async method
HardNorth Sep 13, 2023
4463ba2
Add launch_id getter for backward compatibility
HardNorth Sep 13, 2023
44460dd
Refactoring: move common logic for Threaded and Batched clients to ab…
HardNorth Sep 13, 2023
c8ff14f
Add TODO
HardNorth Sep 13, 2023
37f1c07
Fix some typing
HardNorth Sep 13, 2023
11dbee1
Refactoring: move common interface to root
HardNorth Sep 14, 2023
8672fec
Add ThreadedTask class and its factory
HardNorth Sep 14, 2023
d468aa2
Remove unused module
HardNorth Sep 14, 2023
23878d8
Constant refactoring
HardNorth Sep 14, 2023
424b9c6
Class rename
HardNorth Sep 14, 2023
5fefe6d
Add log batching
HardNorth Sep 14, 2023
55f471f
Add log batching
HardNorth Sep 14, 2023
ea0592c
Add log batching
HardNorth Sep 14, 2023
07a8583
Fix issues
HardNorth Sep 14, 2023
ad21f3e
Fix issues
HardNorth Sep 14, 2023
8849ed3
Fix issues
HardNorth Sep 14, 2023
7395f5c
revert argument rename
HardNorth Sep 14, 2023
5d90513
Fix object cloning
HardNorth Sep 14, 2023
ab2c919
Fix issues
HardNorth Sep 14, 2023
18a0dcf
Fix issues
HardNorth Sep 14, 2023
4f5c3f2
Fix issues
HardNorth Sep 14, 2023
507fa09
Fix issues
HardNorth Sep 14, 2023
7e70eb4
Fix parallel execution issues
HardNorth Sep 15, 2023
00cd206
Fix payload generation
HardNorth Sep 15, 2023
7095219
Bypass log batcher
HardNorth Sep 15, 2023
69ecbb0
Update tasks API
HardNorth Sep 15, 2023
c8763fb
Add task list class
HardNorth Sep 15, 2023
5d5f46a
Fix circular import
HardNorth Sep 15, 2023
d12aad1
Fix decorator order
HardNorth Sep 15, 2023
9e10d24
Fix constructor argument
HardNorth Sep 15, 2023
d4cd413
Fix list init
HardNorth Sep 15, 2023
95c7b0a
Add loop bypass
HardNorth Sep 15, 2023
cd0b90f
Simplify inits
HardNorth Sep 15, 2023
dab6a57
Add endpoint property
HardNorth Sep 15, 2023
358dd5a
Recursion fix
HardNorth Sep 15, 2023
a4e1352
Add log batcher bypass
HardNorth Sep 15, 2023
79e2f8d
Add project property
HardNorth Sep 16, 2023
9fc94f0
Add task repr and str methods
HardNorth Sep 16, 2023
d29cf33
Add task repr and str methods
HardNorth Sep 16, 2023
566830c
Add log append on launch finish
HardNorth Sep 16, 2023
cd2e717
Fix task wait
HardNorth Sep 16, 2023
0723510
Fix ThreadedRPClient
HardNorth Sep 18, 2023
62a01c9
Fix ThreadedRPClient
HardNorth Sep 18, 2023
3427713
Fix ThreadedRPClient
HardNorth Sep 18, 2023
26ac3ad
Fix ThreadedRPClient
HardNorth Sep 18, 2023
e3c9a08
Fix logging at the end of reporting
HardNorth Sep 19, 2023
e90a8f8
Add client closing on Launch finish
HardNorth Sep 20, 2023
3166cf7
Add client closing on Launch finish
HardNorth Sep 20, 2023
519cb6f
Refactor task timeouts
HardNorth Sep 20, 2023
c38ccb3
Fix HTTP session close
HardNorth Sep 20, 2023
2ebefa4
Misprint fix
HardNorth Sep 20, 2023
c4d2403
Remove Python 2.7 artifacts
HardNorth Sep 20, 2023
6c24c4d
Add HTTP Retry client
HardNorth Sep 20, 2023
a21a584
Remove six
HardNorth Sep 20, 2023
bf905a2
Decrease library requirements
HardNorth Sep 20, 2023
e925bec
Finish HTTP Retry client
HardNorth Sep 20, 2023
ca263d2
Fix Enum init
HardNorth Sep 20, 2023
71f994c
Update aiohttp requirement
HardNorth Sep 20, 2023
5397a7e
Update aiohttp requirement
HardNorth Sep 20, 2023
4bbaaf8
Update retry delay logic
HardNorth Sep 21, 2023
5470f98
remove sympy
HardNorth Sep 21, 2023
ace25fe
Fix delays
HardNorth Sep 21, 2023
c7d577e
Add the first retry test
HardNorth Sep 21, 2023
d381163
Fix some tests
HardNorth Sep 21, 2023
0374753
Python version compatibility fix
HardNorth Sep 21, 2023
c0208db
Python version compatibility fix
HardNorth Sep 21, 2023
37a7c33
Python version compatibility fix
HardNorth Sep 21, 2023
c876c44
Python version compatibility fix
HardNorth Sep 21, 2023
4b6e82d
Fixes for tests
HardNorth Sep 22, 2023
892a43a
Fixes for tests
HardNorth Sep 22, 2023
cf13d6e
Fix tests
HardNorth Sep 22, 2023
81f47de
Fix tests
HardNorth Sep 22, 2023
74d6bc5
Fix tests
HardNorth Sep 22, 2023
2d90a8f
Fix tests
HardNorth Sep 22, 2023
42c292e
Fix tests
HardNorth Sep 22, 2023
d698d98
Fix flake8
HardNorth Sep 22, 2023
f517fc5
Fix flake8
HardNorth Sep 22, 2023
30341b8
Fix flake8
HardNorth Sep 22, 2023
cce6f57
Move LifoQueue to helpers and add pydocs
HardNorth Sep 23, 2023
5f2dc9b
Add pydocs
HardNorth Sep 23, 2023
b9c4dd6
Update interfaces signatures
HardNorth Sep 25, 2023
8300ef1
Add pydocs and fix interfaces
HardNorth Sep 25, 2023
6ec904d
Update pydocs, interfaces and properties
HardNorth Sep 25, 2023
7b8fb85
Fix tests
HardNorth Sep 25, 2023
47dc18c
Add getters
HardNorth Sep 25, 2023
5ba1a79
Fix typing
HardNorth Sep 25, 2023
940435d
Fix use_own_launch property
HardNorth Sep 25, 2023
ffafa27
Fix tests
HardNorth Sep 25, 2023
97afbc9
Pydocs and type hinting fixes
HardNorth Sep 25, 2023
65dabc0
Pydocs add
HardNorth Sep 25, 2023
7aee6eb
Unify ReportPortal name
HardNorth Sep 25, 2023
aaf8361
Changelog update
autoreportportal Sep 25, 2023
7f25d4b
Version update
autoreportportal Sep 25, 2023
9f84968
Merge branch 'develop' into rp-client-async
HardNorth Sep 25, 2023
79c9b9e
flake8 fixes
HardNorth Sep 25, 2023
d646a98
Add pydocs
HardNorth Sep 26, 2023
d95e56a
Add pydocs
HardNorth Sep 26, 2023
2e50a53
Remove redundant package data
HardNorth Sep 26, 2023
98d89d4
Unify 'returns' keyword
HardNorth Sep 26, 2023
0fdf478
Update pydocs
HardNorth Sep 26, 2023
47dc7d5
Update pydocs
HardNorth Sep 26, 2023
b21c76f
Add exception handling in case of connection errors, update pydocs.
HardNorth Sep 26, 2023
ec5f8dc
Update pydocs.
HardNorth Sep 26, 2023
5fc8b64
Update pydocs.
HardNorth Sep 26, 2023
27d78f8
Update pydocs. And import fixes.
HardNorth Sep 26, 2023
3c52746
Fix typing
HardNorth Sep 26, 2023
6125293
Add pydocs
HardNorth Sep 26, 2023
095a6c5
Update pydocs
HardNorth Sep 27, 2023
47b66e9
Update pydocs
HardNorth Sep 27, 2023
11b1ebb
Update pydocs
HardNorth Sep 27, 2023
cb59f2a
Update pydocs
HardNorth Sep 28, 2023
3ca6e97
Update pydocs
HardNorth Sep 28, 2023
ac76d44
Update pydocs
HardNorth Sep 28, 2023
bdb81c4
Fix session config
HardNorth Sep 28, 2023
22418a4
Add more tests
HardNorth Sep 28, 2023
a938efd
Ignore tests for Python 3.7
HardNorth Sep 28, 2023
73870cc
Add more tests
HardNorth Sep 28, 2023
00ddcc1
Add get/set state methods
HardNorth Sep 29, 2023
d67f6b3
Fixes and tests for pickling
HardNorth Sep 29, 2023
8004c78
CHANGELOG.md update
HardNorth Sep 29, 2023
effce03
Implement own LifoQueue
HardNorth Sep 29, 2023
1383551
Update pydocs
HardNorth Sep 29, 2023
21686fc
Fix flake8
HardNorth Sep 29, 2023
bcd5819
Remove redundant package files
HardNorth Oct 2, 2023
5d50669
Add 'test_async_send_event'
HardNorth Oct 2, 2023
a09b2ff
Fix for Python 3.7
HardNorth Oct 2, 2023
c8c4081
Rename test module
HardNorth Oct 2, 2023
b7203b1
Move code style checks on Python 3.8
HardNorth Oct 2, 2023
c62a571
Refactor aio client tests
HardNorth Oct 2, 2023
c2af6b0
Update retries settings logic and add tests
HardNorth Oct 2, 2023
5b4460e
Add timeout argument tests
HardNorth Oct 2, 2023
cbf34eb
Fix tests
HardNorth Oct 2, 2023
c45dd14
Fix tests
HardNorth Oct 2, 2023
684b8ea
Add clone test
HardNorth Oct 3, 2023
b3cb433
Correct pydoc line length
HardNorth Oct 3, 2023
13487dd
Add clone test
HardNorth Oct 3, 2023
290319f
Add clone test
HardNorth Oct 3, 2023
9577a0f
Add clone test
HardNorth Oct 3, 2023
ac3f5d5
Fix for Python 3.7
HardNorth Oct 3, 2023
5f9b2fc
Fix for Python 3.7
HardNorth Oct 3, 2023
1c94489
Use 'importlib.metadata' for package data extraction for Python versi…
HardNorth Oct 3, 2023
769e609
CHANGELOG.md update
HardNorth Oct 3, 2023
5925cc7
Fix for Python 3.7
HardNorth Oct 3, 2023
e0c1e17
A try to fix tests for python 3.8, 3.9
HardNorth Oct 3, 2023
e3035f3
Client.session method made async
HardNorth Oct 3, 2023
54f5be8
Add test skip
HardNorth Oct 3, 2023
0ae3df1
Add Python 3.12 to supported versions
HardNorth Oct 4, 2023
0ea9b9a
A try to fix build for Python 3.12
HardNorth Oct 4, 2023
a8c2443
Revert "A try to fix build for Python 3.12"
HardNorth Oct 4, 2023
f83f573
Revert "Add Python 3.12 to supported versions"
HardNorth Oct 4, 2023
43035f5
Add launch url tests
HardNorth Oct 4, 2023
ecefaa5
Remove unused code
HardNorth Oct 4, 2023
8279add
Remove unused code
HardNorth Oct 4, 2023
1d3f815
Add debug printing
HardNorth Oct 4, 2023
f905945
Fix warning which affects other tests
HardNorth Oct 4, 2023
7929da7
Fix flake8
HardNorth Oct 4, 2023
90a033d
Refactor RetryingClientSession class
HardNorth Oct 4, 2023
e91bb14
Fix docstrings and close method
HardNorth Oct 4, 2023
0d597e9
Remove debug print
HardNorth Oct 4, 2023
446387e
Update http module
HardNorth Oct 5, 2023
d996fe0
Update http module
HardNorth Oct 5, 2023
f4bdd09
Refactor package parameters get
HardNorth Oct 5, 2023
65a139d
Fix for Python 3.7
HardNorth Oct 5, 2023
efefdde
Fix warnings for Python versions > 3.7
HardNorth Oct 5, 2023
5909f21
Fix coverage
HardNorth Oct 5, 2023
3a97f27
Add a comment
HardNorth Oct 5, 2023
2cbbf73
Update clone test
HardNorth Oct 5, 2023
6861419
Refactoring, hide some classes from outsiders
HardNorth Oct 5, 2023
d093b51
Fix build
HardNorth Oct 5, 2023
7c5324c
Fix tests
HardNorth Oct 5, 2023
429b1f2
Refactoring of client closing
HardNorth Oct 6, 2023
af9ab51
fix build
HardNorth Oct 6, 2023
57c0d00
A try to fix build
HardNorth Oct 6, 2023
a7c1d2c
Fix build
HardNorth Oct 6, 2023
bbe95ab
Fix flake8
HardNorth Oct 6, 2023
853e5fd
Fix flake8
HardNorth Oct 6, 2023
2f9a8f6
Fix task completion logic
HardNorth Oct 6, 2023
bbc2a18
Update connection closing logic
HardNorth Oct 6, 2023
9b6c008
Refactor client closing logic
HardNorth Oct 9, 2023
3641521
Add SSL tests
HardNorth Oct 9, 2023
c233e11
Enable SSL tests for python 3.7
HardNorth Oct 9, 2023
6dea905
Fix tests
HardNorth Oct 9, 2023
265e0d8
Disable tests for Python 3.7
HardNorth Oct 9, 2023
a0e78d1
Add close method test
HardNorth Oct 9, 2023
7e772bd
Type corrections
HardNorth Oct 10, 2023
548e985
Add start launch tests
HardNorth Oct 10, 2023
8fc3a73
Fix build
HardNorth Oct 10, 2023
1e1a206
A try to fix tests
HardNorth Oct 10, 2023
27a2042
A try to fix tests
HardNorth Oct 10, 2023
a73bae2
Launch print tests
HardNorth Oct 10, 2023
6808b70
Format fix
HardNorth Oct 10, 2023
3ac1ba0
Add connection error tests
HardNorth Oct 10, 2023
efb029d
Fix tests
HardNorth Oct 10, 2023
5fe8fd3
Fix for Python 3.7
HardNorth Oct 10, 2023
a483310
Fix tests
HardNorth Oct 10, 2023
01f6f94
Add more tests
HardNorth Oct 10, 2023
c698f34
Fix tests
HardNorth Oct 10, 2023
32744f6
Fix tests for Python 3.7
HardNorth Oct 10, 2023
47ec1f8
Add test_start_test_item
HardNorth Oct 10, 2023
e9578c2
Update helpers.verify_value_length function
HardNorth Oct 11, 2023
0f7f4d6
Add more aio client tests
HardNorth Oct 11, 2023
fa64a56
Fix tests
HardNorth Oct 11, 2023
9a37e98
Add pydocs
HardNorth Oct 11, 2023
22d1ec6
Update CHANGELOG.md
HardNorth Oct 11, 2023
25b816b
Add more tests
HardNorth Oct 11, 2023
85d187a
Add more tests
HardNorth Oct 11, 2023
eda0c70
Add more tests
HardNorth Oct 11, 2023
2042520
Add more tests
HardNorth Oct 12, 2023
291eff5
Add more tests
HardNorth Oct 12, 2023
6f268b1
Update test
HardNorth Oct 12, 2023
3476496
Add more tests
HardNorth Oct 12, 2023
7479384
Add more tests
HardNorth Oct 12, 2023
b79b664
Add more tests
HardNorth Oct 12, 2023
979e7f3
Add more tests
HardNorth Oct 12, 2023
7ecb535
Merge pull request #220 from reportportal/rp-client-async
HardNorth Oct 12, 2023
ad146e6
Add factory function
HardNorth Oct 13, 2023
5bd01d2
Fix flake8
HardNorth Oct 13, 2023
117ca91
Add missed types
HardNorth Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ jobs:
pip install tox tox-gh-actions

- name: Test with tox
timeout-minutes: 10
run: tox

- name: Upload coverage to Codecov
if: matrix.python-version == 3.7 && success()
if: matrix.python-version == 3.8 && success()
uses: codecov/codecov-action@v3
with:
files: coverage.xml
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog

## [Unreleased]
### Added
- `RP` class in `reportportal_client.client` module as common interface for all ReportPortal clients, by @HardNorth
- `reportportal_client.aio` with asynchronous clients and auxiliary classes, by @HardNorth
- Dependency on `aiohttp` and `certifi`, by @HardNorth
### Changed
- RPClient class does not use separate Thread for log processing anymore, by @HardNorth
- Use `importlib.metadata` package for distribution data extraction for Python versions starting 3.8, by @HardNorth
- `helpers.verify_value_length` function updated to truncate attribute keys also and reveal attributes were truncated, by @HardNorth
### Removed
- Dependency on `six`, by @HardNorth

## [5.4.1]
### Changed
- Unified ReportPortal product naming, by @HardNorth
- `RPClient` internal item stack implementation changed to `LifoQueue` to maintain concurrency better, by @HardNorth
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include MANIFEST.in
include README.md CONTRIBUTING.rst requirements.txt
exclude test_res/*
130 changes: 113 additions & 17 deletions reportportal_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,124 @@
"""
Copyright (c) 2022 https://reportportal.io .
# Copyright (c) 2023 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
"""This package is the base package for ReportPortal client."""
import typing
import warnings

https://www.apache.org/licenses/LICENSE-2.0
import aenum

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# noinspection PyProtectedMember
from reportportal_client._internal.local import current, set_current
from reportportal_client.aio.client import AsyncRPClient, BatchedRPClient, ThreadedRPClient
from reportportal_client.client import RP, RPClient, OutputType
from reportportal_client.logs import RPLogger, RPLogHandler
from reportportal_client.steps import step


class ClientType(aenum.Enum):
"""Enum of possible type of ReportPortal clients."""

SYNC = aenum.auto()
ASYNC = aenum.auto()
ASYNC_THREAD = aenum.auto()
ASYNC_BATCHED = aenum.auto()


# noinspection PyIncorrectDocstring
def create_client(
client_type: ClientType,
endpoint: str,
project: str,
*,
api_key: str = None,
**kwargs: typing.Any
) -> typing.Optional[RP]:
"""Create and ReportPortal Client based on the type and arguments provided.

:param client_type: Type of the Client to create.
:type client_type: ClientType
:param endpoint: Endpoint of the ReportPortal service.
:type endpoint: str
:param project: Project name to report to.
:type project: str
:param api_key: Authorization API key.
:type api_key: str
:param launch_uuid: A launch UUID to use instead of starting own one.
:type launch_uuid: str
:param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the server
side.
:type is_skipped_an_issue: bool
:param verify_ssl: Option to skip ssl verification.
:type verify_ssl: typing.Union[bool, str]
:param retries: Number of retry attempts to make in case of connection / server
errors.
:type retries: int
:param max_pool_size: Option to set the maximum number of connections to save the pool.
:type max_pool_size: int
:param http_timeout : A float in seconds for connect and read timeout. Use a Tuple to
specific connect and read separately.
:type http_timeout: Tuple[float, float]
:param mode: Launch mode, all Launches started by the client will be in that mode.
:type mode: str
:param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
:type launch_uuid_print: bool
:param print_output: Set output stream for Launch UUID printing.
:type print_output: OutputType
:param log_batch_size: Option to set the maximum number of logs that can be processed in one
batch.
:type log_batch_size: int
:param log_batch_payload_limit: Maximum size in bytes of logs that can be processed in one batch.
:type log_batch_payload_limit: int
:param keepalive_timeout: For Async Clients only. Maximum amount of idle time in seconds before
force connection closing.
:type keepalive_timeout: int
:param task_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for a
Task processing.
:type task_timeout: float
:param shutdown_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for
shutting down internal Tasks.
:type shutdown_timeout: float
:param trigger_num: For Async Batched Client only. Number of tasks which triggers Task batch
execution.
:type trigger_num: int
:param trigger_interval: For Async Batched Client only. Time limit which triggers Task batch
execution.
:type trigger_interval: float
:return: ReportPortal Client instance.
"""
if client_type is ClientType.SYNC:
return RPClient(endpoint, project, api_key=api_key, **kwargs)
if client_type is ClientType.ASYNC:
return AsyncRPClient(endpoint, project, api_key=api_key, **kwargs)
if client_type is ClientType.ASYNC_THREAD:
return ThreadedRPClient(endpoint, project, api_key=api_key, **kwargs)
if client_type is ClientType.ASYNC_BATCHED:
return BatchedRPClient(endpoint, project, api_key=api_key, **kwargs)
warnings.warn(f'Unknown ReportPortal Client type requested: {client_type}', RuntimeWarning, stacklevel=2)

from ._local import current
from .logs import RPLogger, RPLogHandler
from .client import RPClient
from .steps import step

__all__ = [
'ClientType',
'create_client',
'current',
'set_current',
'RP',
'RPClient',
'AsyncRPClient',
'BatchedRPClient',
'ThreadedRPClient',
'OutputType',
'RPLogger',
'RPLogHandler',
'RPClient',
'step',
]
14 changes: 14 additions & 0 deletions reportportal_client/_internal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

"""ReportPortal client internal API. No warnings before breaking changes. No backward compatibility."""
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""This package contains unit tests for logging."""

# Copyright (c) 2022 EPAM Systems
# Copyright (c) 2023 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
164 changes: 164 additions & 0 deletions reportportal_client/_internal/aio/http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright (c) 2023 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

"""This module designed to help with asynchronous HTTP request/response handling."""

import asyncio
import sys
from types import TracebackType
from typing import Coroutine, Any, Optional, Type, Callable

from aenum import Enum
from aiohttp import ClientSession, ClientResponse, ServerConnectionError, \
ClientResponseError

DEFAULT_RETRY_NUMBER: int = 5
DEFAULT_RETRY_DELAY: float = 0.005
THROTTLING_STATUSES: set = {425, 429}
RETRY_STATUSES: set = {408, 500, 502, 503, 504, 507}.union(THROTTLING_STATUSES)


class RetryClass(int, Enum):
"""Enum contains error types and their retry delay multiply factor as values."""

SERVER_ERROR = 1
CONNECTION_ERROR = 2
THROTTLING = 3


class RetryingClientSession:
"""Class uses aiohttp.ClientSession.request method and adds request retry logic."""

_client: ClientSession
__retry_number: int
__retry_delay: float

def __init__(
self,
*args,
max_retry_number: int = DEFAULT_RETRY_NUMBER,
base_retry_delay: float = DEFAULT_RETRY_DELAY,
**kwargs
):
"""Initialize an instance of the session with arguments.

To obtain the full list of arguments please see aiohttp.ClientSession.__init__() method. This class
just bypass everything to the base method, except two local arguments 'max_retry_number' and
'base_retry_delay'.

:param max_retry_number: the maximum number of the request retries if it was unsuccessful
:param base_retry_delay: base value for retry delay, determine how much time the class will wait after
an error. Real value highly depends on Retry Class and Retry attempt number,
since retries are performed in exponential delay manner
"""
self._client = ClientSession(*args, **kwargs)
self.__retry_number = max_retry_number
self.__retry_delay = base_retry_delay

async def __nothing(self):
pass

def __sleep(self, retry_num: int, retry_factor: int) -> Coroutine:
if retry_num > 0: # don't wait at the first retry attempt
delay = (((retry_factor * self.__retry_delay) * 1000) ** retry_num) / 1000
return asyncio.sleep(delay)
else:
return self.__nothing()

async def __request(
self, method: Callable, url, **kwargs: Any
) -> ClientResponse:
"""Make a request and retry if necessary.

The method retries requests depending on error class and retry number. For no-retry errors, such as
400 Bad Request it just returns result, for cases where it's reasonable to retry it does it in
exponential manner.
"""
result = None
exceptions = []
for i in range(self.__retry_number + 1): # add one for the first attempt, which is not a retry
retry_factor = None
try:
result = await method(url, **kwargs)
except Exception as exc:
exceptions.append(exc)
if isinstance(exc, ServerConnectionError) or isinstance(exc, ClientResponseError):
retry_factor = RetryClass.CONNECTION_ERROR

if not retry_factor:
raise exc

if result:
if result.ok or result.status not in RETRY_STATUSES:
return result

if result.status in THROTTLING_STATUSES:
retry_factor = RetryClass.THROTTLING
else:
retry_factor = RetryClass.SERVER_ERROR

if i + 1 < self.__retry_number:
# don't wait at the last attempt
await self.__sleep(i, retry_factor)

if exceptions:
if len(exceptions) > 1:
if sys.version_info > (3, 10):
# noinspection PyCompatibility
raise ExceptionGroup( # noqa: F821
'During retry attempts the following exceptions happened',
exceptions
)
else:
raise exceptions[-1]
else:
raise exceptions[0]
return result

def get(self, url: str, *, allow_redirects: bool = True,
**kwargs: Any) -> Coroutine[Any, Any, ClientResponse]:
"""Perform HTTP GET request."""
return self.__request(self._client.get, url, allow_redirects=allow_redirects, **kwargs)

def post(self, url: str, *, data: Any = None, **kwargs: Any) -> Coroutine[Any, Any, ClientResponse]:
"""Perform HTTP POST request."""
return self.__request(self._client.post, url, data=data, **kwargs)

def put(self, url: str, *, data: Any = None, **kwargs: Any) -> Coroutine[Any, Any, ClientResponse]:
"""Perform HTTP PUT request."""
return self.__request(self._client.put, url, data=data, **kwargs)

def close(self) -> Coroutine:
"""Gracefully close internal aiohttp.ClientSession class instance."""
return self._client.close()

async def __aenter__(self) -> "RetryingClientSession":
"""Auxiliary method which controls what `async with` construction does on block enter."""
return self

async def __aexit__(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None:
"""Auxiliary method which controls what `async with` construction does on block exit."""
await self.close()
Loading