Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Refactoring] Default port manager functions now use PortManager__Generic and LocalOperations #251

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
[BUG FIX] PortManager__ThisHost::__new__ had MT-problem
After MT-lock we must to check __class__.sm_single_instance again.

Refactoring
 - PortManager__ThisHost::__new__ is replaced with an explicit PortManager__ThisHost::get_single_instance()
 - PortManager__ThisHost::__init__ is deleted
  • Loading branch information
dmitry-lipetsk committed May 5, 2025
commit f87d559790de6ecc47b4941b573ba6a1e6935c10
18 changes: 10 additions & 8 deletions testgres/impl/port_manager__this_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ class PortManager__ThisHost(PortManager):
sm_single_instance: PortManager = None
sm_single_instance_guard = threading.Lock()

def __init__(self):
pass

def __new__(cls) -> PortManager:
@staticmethod
def get_single_instance() -> PortManager:
assert __class__ == PortManager__ThisHost
assert __class__.sm_single_instance_guard is not None

if __class__.sm_single_instance is None:
with __class__.sm_single_instance_guard:
__class__.sm_single_instance = super().__new__(cls)
assert __class__.sm_single_instance
if __class__.sm_single_instance is not None:
assert type(__class__.sm_single_instance) == __class__ # noqa: E721
return __class__.sm_single_instance

with __class__.sm_single_instance_guard:
if __class__.sm_single_instance is None:
__class__.sm_single_instance = __class__()
assert __class__.sm_single_instance is not None
assert type(__class__.sm_single_instance) == __class__ # noqa: E721
return __class__.sm_single_instance

Expand Down
2 changes: 1 addition & 1 deletion testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def _get_port_manager(os_ops: OsOperations) -> PortManager:
assert isinstance(os_ops, OsOperations)

if isinstance(os_ops, LocalOperations):
return PortManager__ThisHost()
return PortManager__ThisHost.get_single_instance()

# TODO: Throw the exception "Please define a port manager." ?
return PortManager__Generic(os_ops)
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/global_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OsOpsDescrs:
class PortManagers:
sm_remote_port_manager = PortManager__Generic(OsOpsDescrs.sm_remote_os_ops)

sm_local_port_manager = PortManager__ThisHost()
sm_local_port_manager = PortManager__ThisHost.get_single_instance()

sm_local2_port_manager = PortManager__Generic(OsOpsDescrs.sm_local_os_ops)

Expand Down