Skip to content

Commit

Permalink
Add test to reproduce non-removed IPC socket file
Browse files Browse the repository at this point in the history
  • Loading branch information
Peque committed Apr 6, 2018
1 parent 32ba69b commit 8eff203
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
13 changes: 11 additions & 2 deletions osbrain/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1696,13 +1696,22 @@ def is_running(self):
"""
return self._running

def _clean_up_before_kill(self):
"""
Clean-up process before dying:
- Close all external sockets.
- Stop all timers.
"""
self.stop_all_timers()
self.close_all()

def kill(self):
"""
Force shutdown of the agent.
"""
self._pyroDaemon.shutdown()
self.stop_all_timers()
self.close_all()
self._clean_up_before_kill()

def _get_unique_external_zmq_sockets(self):
"""
Expand Down
23 changes: 23 additions & 0 deletions osbrain/tests/test_bugs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""
Test file for bugs found in osbrain.
"""
import time
import sys

from osbrain import Agent
from osbrain import run_agent
from osbrain.helper import agent_dies
from osbrain.helper import wait_condition
from osbrain.helper import wait_agent_condition

from common import nsproxy # noqa: F401
Expand All @@ -25,3 +29,22 @@ def inc(agent):
limit = sys.getrecursionlimit()
assert wait_agent_condition(agent, lambda agent: agent.count > limit,
timeout=10)


def test_slow_clean_up_socket_files(nsproxy):
"""
Even if the clean-up process is slow, IPC socket files should always be
cleaned. This test was created to ensure that the clean-up process is
executed before the agent's daemon shutdown when the agent is killed.
"""
class Lazy(Agent):
def _clean_up(self):
time.sleep(0.5)
super()._clean_up()

agent = run_agent('a0', base=Lazy)
address = agent.bind('PUSH')
agent.oneway.kill()

assert agent_dies('name', nsproxy)
assert wait_condition(address.address.exists, negate=True)

0 comments on commit 8eff203

Please sign in to comment.