summaryrefslogtreecommitdiff
path: root/src/mailman/commands/tests/test_control.py
diff options
context:
space:
mode:
authorBarry Warsaw2015-11-01 15:44:23 -0500
committerBarry Warsaw2015-11-01 15:52:03 -0500
commit212127e9374ec6791a90306f176d1961b3befc67 (patch)
treee25a719790ff0f99715203c66002c2dfda0b3d39 /src/mailman/commands/tests/test_control.py
parent49fff6df2add54fa2c195ca734b00bfe9f275c5c (diff)
downloadmailman-212127e9374ec6791a90306f176d1961b3befc67.tar.gz
mailman-212127e9374ec6791a90306f176d1961b3befc67.tar.zst
mailman-212127e9374ec6791a90306f176d1961b3befc67.zip
Diffstat (limited to 'src/mailman/commands/tests/test_control.py')
-rw-r--r--src/mailman/commands/tests/test_control.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/mailman/commands/tests/test_control.py b/src/mailman/commands/tests/test_control.py
index 7163f728c..ea806485c 100644
--- a/src/mailman/commands/tests/test_control.py
+++ b/src/mailman/commands/tests/test_control.py
@@ -18,6 +18,7 @@
"""Test some additional corner cases for starting/stopping."""
__all__ = [
+ 'TestBinDir',
'TestStart',
'find_master',
'make_config',
@@ -33,10 +34,13 @@ import shutil
import socket
import unittest
+from contextlib import ExitStack
from datetime import timedelta, datetime
from mailman.commands.cli_control import Start, kill_watcher
-from mailman.config import config
+from mailman.config import Configuration, config
+from mailman.testing.helpers import configuration
from mailman.testing.layers import ConfigLayer
+from tempfile import TemporaryDirectory
SEP = '|'
@@ -159,3 +163,54 @@ class TestStart(unittest.TestCase):
self.command.process(self.args)
pid = find_master()
self.assertNotEqual(pid, None)
+
+
+
+class TestBinDir(unittest.TestCase):
+ """Test issues related to bin_dir, e.g. issue #3"""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self.command = Start()
+ self.command.parser = FakeParser()
+ self.args = FakeArgs()
+ self.args.config = make_config()
+
+ def test_master_is_elsewhere(self):
+ with ExitStack() as resources:
+ # Patch os.fork() so that we can record the failing child process's
+ # id. We need to wait on the child exiting in either case, and
+ # when it fails, no master.pid will be written.
+ bin_dir = resources.enter_context(TemporaryDirectory())
+ old_master = os.path.join(config.BIN_DIR, 'master')
+ new_master = os.path.join(bin_dir, 'master')
+ shutil.move(old_master, new_master)
+ resources.callback(shutil.move, new_master, old_master)
+ # Starting mailman should fail because 'master' can't be found.
+ # XXX This will print Errno 2 on the console because we're not
+ # silencing the child process's stderr.
+ self.command.process(self.args)
+ # There should be no pid file.
+ args_config = Configuration()
+ args_config.load(self.args.config)
+ self.assertFalse(os.path.exists(args_config.PID_FILE))
+ os.wait()
+
+ def test_master_is_elsewhere_and_findable(self):
+ with ExitStack() as resources:
+ bin_dir = resources.enter_context(TemporaryDirectory())
+ old_master = os.path.join(config.BIN_DIR, 'master')
+ new_master = os.path.join(bin_dir, 'master')
+ shutil.move(old_master, new_master)
+ resources.enter_context(
+ configuration('paths.testing', bin_dir=bin_dir))
+ resources.callback(shutil.move, new_master, old_master)
+ # Starting mailman should find master in the new bin_dir.
+ self.command.process(self.args)
+ # There should a pid file and the process it describes should be
+ # killable. We might have to wait until the process has started.
+ master_pid = find_master()
+ self.assertIsNotNone(master_pid, 'master did not start')
+ os.kill(master_pid, signal.SIGTERM)
+ os.waitpid(master_pid, 0)