Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 2 additions & 8 deletions mongo_orchestration/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys
import time

from signal import SIGTERM, SIGKILL
from signal import SIGTERM

DEVNULL = open(os.devnull, 'r+b')

Expand Down Expand Up @@ -174,15 +174,8 @@ def stop(self):
# Try killing the daemon process
try:
os.kill(pid, SIGTERM)
t0 = time.time()
while is_unix_process_running(pid):
time.sleep(0.25)
# After 5 seconds resend a SIGTERM to the process.
if time.time() - t0 > 5:
os.kill(pid, SIGTERM)
# After 10 seconds send a SIGKILL to the process.
if time.time() - t0 > 10:
os.kill(pid, SIGKILL)
except OSError as err:
if err.errno == errno.ESRCH:
if os.path.exists(self.pidfile):
Expand Down Expand Up @@ -216,3 +209,4 @@ def is_unix_process_running(pid):
else:
raise err
return True

18 changes: 15 additions & 3 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def run(cmd, **kwargs):
if proc.returncode != 0:
raise RuntimeError('Process failed!')


def stop():
pid = Path("server.pid").read_text().strip()
os.kill(int(pid), signal.SIGTERM)
Path("server.pid").unlink()

class TestLaunch(unittest.TestCase):

def test_launch_single(self):
Expand All @@ -37,7 +43,9 @@ def test_launch_single(self):
proc.send('q\n')
proc.wait()
self.assertEqual(proc.exitstatus, 0)
run('mongo-orchestration stop')
# TODO: https://jira.mongodb.org/browse/PYTHON-5594
# run('mongo-orchestration stop')
stop()

def test_launch_replica_set(self):
if os.name != 'posix':
Expand All @@ -48,7 +56,9 @@ def test_launch_replica_set(self):
proc.send('q\n')
proc.wait()
self.assertEqual(proc.exitstatus, 0)
run('mongo-orchestration stop')
# TODO: https://jira.mongodb.org/browse/PYTHON-5594
# run('mongo-orchestration stop')
stop()


def test_launch_sharded(self):
Expand All @@ -60,4 +70,6 @@ def test_launch_sharded(self):
proc.send('q\n')
proc.wait()
self.assertEqual(proc.exitstatus, 0)
run('mongo-orchestration stop')
# TODO: https://jira.mongodb.org/browse/PYTHON-5594
# run('mongo-orchestration stop')
stop()