Commit 936d5cad authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[1428] Accept sockets and keep them

parent d6d7a352
......@@ -246,6 +246,7 @@ class BoB:
self._socket_path = None
self._tmpdir = None
self._srv_socket = None
self._unix_sockets = {}
def __propagate_component_config(self, config):
comps = dict(config)
......@@ -871,6 +872,8 @@ class BoB:
Accept a socket from the unix domain socket server and put it to the
others we care about.
"""
socket = self._srv_socket.accept()
self._unix_sockets[socket.fileno()] = (socket, '')
def run(self, wakeup_fd):
"""
......
......@@ -952,8 +952,15 @@ class SocketSrvTest(unittest.TestCase):
"""
A mock socket for the select and accept and stuff like that.
"""
def __init__(self, owner, fileno=42):
self.__owner = owner
self.__fileno = fileno
def fileno(self):
return 42
return self.__fileno
def accept(self):
return self.__class__(self.__owner, 13)
class __CCS:
"""
......@@ -984,7 +991,7 @@ class SocketSrvTest(unittest.TestCase):
socket is readable.
"""
self.__boss.runnable = True
self.__boss._srv_socket = self.__FalseSocket()
self.__boss._srv_socket = self.__FalseSocket(self)
self.__boss._srv_accept = self.__accept
self.__boss.ccs = self.__CCS()
bind10_src.select.select = self.__select_accept
......@@ -994,6 +1001,19 @@ class SocketSrvTest(unittest.TestCase):
# And the select had the right parameters
self.assertEqual(([2, 1, 42], [], [], None), self.__select_called)
def test_srv_accept(self):
"""
Test how the _srv_accept method works.
"""
self.__boss._srv_socket = self.__FalseSocket(self)
self.__boss._srv_accept()
# After we accepted, a new socket is added there
socket = self.__boss._unix_sockets[13][0]
# The socket is properly stored there
self.assertIsInstance(socket, self.__FalseSocket)
# And the buffer (yet empty) is there
self.assertEqual({13: (socket, '')}, self.__boss._unix_sockets)
if __name__ == '__main__':
# store os.environ for test_unchanged_environment
original_os_environ = copy.deepcopy(os.environ)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment