Skip to content

Commit

Permalink
Clean up more singleton cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz authored and garethgreenaway committed Sep 15, 2021
1 parent d5a16a1 commit 0f9c031
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 55 deletions.
26 changes: 0 additions & 26 deletions salt/transport/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,38 +250,12 @@ def __init__(self, opts, **kwargs):
def close(self):
if self._closing:
return

if self._refcount > 1:
# Decrease refcount
with self._refcount_lock:
self._refcount -= 1
log.debug(
"This is not the last %s instance. Not closing yet.",
self.__class__.__name__,
)
return

log.debug("Closing %s instance", self.__class__.__name__)
self._closing = True
self.message_client.close()

# Remove the entry from the instance map so that a closed entry may not
# be reused.
# This forces this operation even if the reference count of the entry
# has not yet gone to zero.
if self.io_loop in self.__class__.instance_map:
loop_instance_map = self.__class__.instance_map[self.io_loop]
if self._instance_key in loop_instance_map:
del loop_instance_map[self._instance_key]
if not loop_instance_map:
del self.__class__.instance_map[self.io_loop]

# pylint: disable=W1701
def __del__(self):
with self._refcount_lock:
# Make sure we actually close no matter if something
# went wrong with our ref counting
self._refcount = 1
try:
self.close()
except OSError as exc:
Expand Down
12 changes: 0 additions & 12 deletions salt/transport/zeromq.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,11 @@ def close(self):
"""
if self._closing:
return

log.debug("Closing %s instance", self.__class__.__name__)
self._closing = True
if hasattr(self, "message_client"):
self.message_client.close()

# Remove the entry from the instance map so that a closed entry may not
# be reused.
# This forces this operation even if the reference count of the entry
# has not yet gone to zero.
if self._io_loop in self.__class__.instance_map:
loop_instance_map = self.__class__.instance_map[self._io_loop]
if self._instance_key in loop_instance_map:
del loop_instance_map[self._instance_key]
if not loop_instance_map:
del self.__class__.instance_map[self._io_loop]

# pylint: disable=W1701
def __del__(self):
try:
Expand Down
17 changes: 0 additions & 17 deletions tests/pytests/unit/transport/test_zeromq.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ def test_master_uri():
) == "tcp://0.0.0.0:{};{}:{}".format(s_port, m_ip, m_port)


def test_force_close_all_instances():
zmq1 = MagicMock()
zmq2 = MagicMock()
zmq3 = MagicMock()
zmq_objects = {"zmq": {"1": zmq1, "2": zmq2}, "other_zmq": {"3": zmq3}}

with patch("salt.transport.zeromq.AsyncZeroMQReqChannel.instance_map", zmq_objects):
salt.transport.zeromq.AsyncZeroMQReqChannel.force_close_all_instances()

assert zmq1.mock_calls == [call.close()]
assert zmq2.mock_calls == [call.close()]
assert zmq3.mock_calls == [call.close()]

# check if instance map changed
assert zmq_objects is salt.transport.zeromq.AsyncZeroMQReqChannel.instance_map


def test_async_req_message_client_pool_send():
sock_pool_size = 5
with patch(
Expand Down

0 comments on commit 0f9c031

Please sign in to comment.