forked from p15670423/monkey
Agent: Add thread ID to SocketsPipe thread name
This commit is contained in:
parent
70978f9b30
commit
4ba4cb583a
|
@ -15,6 +15,8 @@ logger = getLogger(__name__)
|
||||||
class SocketsPipe(Thread):
|
class SocketsPipe(Thread):
|
||||||
"""Manages a pipe between two sockets."""
|
"""Manages a pipe between two sockets."""
|
||||||
|
|
||||||
|
_thread_count: int = 0
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
source,
|
source,
|
||||||
|
@ -25,9 +27,14 @@ class SocketsPipe(Thread):
|
||||||
self.source = source
|
self.source = source
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
super().__init__(name="SocketsPipeThread", daemon=True)
|
super().__init__(name=f"SocketsPipeThread-{self._next_thread_num()}", daemon=True)
|
||||||
self._pipe_closed = pipe_closed
|
self._pipe_closed = pipe_closed
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _next_thread_num(cls):
|
||||||
|
cls._thread_count += 1
|
||||||
|
return cls._thread_count
|
||||||
|
|
||||||
def _pipe(self):
|
def _pipe(self):
|
||||||
sockets = [self.source, self.dest]
|
sockets = [self.source, self.dest]
|
||||||
socket_closed = False
|
socket_closed = False
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from monkey.infection_monkey.network.relay import SocketsPipe
|
||||||
|
|
||||||
|
|
||||||
|
def test_sockets_pipe__name_increments():
|
||||||
|
sock_in = MagicMock()
|
||||||
|
sock_out = MagicMock()
|
||||||
|
|
||||||
|
pipe1 = SocketsPipe(sock_in, sock_out, None)
|
||||||
|
assert pipe1.name.endswith("1")
|
||||||
|
|
||||||
|
pipe2 = SocketsPipe(sock_in, sock_out, None)
|
||||||
|
assert pipe2.name.endswith("2")
|
Loading…
Reference in New Issue