From 7b9824afc9ff8931579761d1ea9a53cd36abf4f1 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 13 Mar 2019 17:56:26 +0200 Subject: [PATCH] Separate method for stopping the bitmessage process and new test case for settings in the generated config, which particularly checks that extralowdifficulty settings are not applied to daemon. --- src/tests/test_config.py | 29 +++++++++++++++++++++++++++++ src/tests/test_process.py | 30 ++++++++++++++++++------------ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/tests/test_config.py b/src/tests/test_config.py index 6817b37a..a0a727e5 100644 --- a/src/tests/test_config.py +++ b/src/tests/test_config.py @@ -2,9 +2,11 @@ Various tests for config """ +import os import unittest from pybitmessage.bmconfigparser import BMConfigParser +from test_process import TestProcessProto class TestConfig(unittest.TestCase): @@ -34,3 +36,30 @@ class TestConfig(unittest.TestCase): BMConfigParser().safeGetInt('nonexistent', 'nonexistent'), 0) self.assertEqual( BMConfigParser().safeGetInt('nonexistent', 'nonexistent', 42), 42) + + +class TestProcessConfig(TestProcessProto): + """A test case for keys.dat""" + + def test_config_defaults(self): + """Test settings in the generated config""" + self._stop_process() + config = BMConfigParser() + config.read(os.path.join(self.home, 'keys.dat')) + + self.assertEquals(config.safeGetInt( + 'bitmessagesettings', 'settingsversion'), 10) + self.assertEquals(config.safeGetInt( + 'bitmessagesettings', 'port'), 8444) + # don't connect + self.assertTrue(config.safeGetBoolean( + 'bitmessagesettings', 'dontconnect')) + # API disabled + self.assertFalse(config.safeGetBoolean( + 'bitmessagesettings', 'apienabled')) + + # extralowdifficulty is false + self.assertEquals(config.safeGetInt( + 'bitmessagesettings', 'defaultnoncetrialsperbyte'), 1000) + self.assertEquals(config.safeGetInt( + 'bitmessagesettings', 'defaultpayloadlengthextrabytes'), 1000) diff --git a/src/tests/test_process.py b/src/tests/test_process.py index c03754a9..73a6e493 100644 --- a/src/tests/test_process.py +++ b/src/tests/test_process.py @@ -47,6 +47,15 @@ class TestProcessProto(unittest.TestCase): except (OSError, IOError): pass + @classmethod + def _stop_process(cls, timeout=5): + cls.process.send_signal(signal.SIGTERM) + try: + cls.process.wait(timeout) + except psutil.TimeoutExpired: + return False + return True + @classmethod def _cleanup_files(cls): for pfile in cls._files: @@ -58,12 +67,12 @@ class TestProcessProto(unittest.TestCase): @classmethod def tearDownClass(cls): """Ensures that pybitmessage stopped and removes files""" - cls.process.send_signal(signal.SIGTERM) try: - cls.process.wait(5) - except psutil.TimeoutExpired: - print(open(os.path.join(cls.home, 'debug.log'), 'rb').read()) - cls.process.kill() + if not cls._stop_process(): + print(open(os.path.join(cls.home, 'debug.log'), 'rb').read()) + cls.process.kill() + except psutil.NoSuchProcess: + pass finally: cls._cleanup_files() @@ -93,13 +102,10 @@ class TestProcessShutdown(TestProcessProto): """Separate test case for SIGTERM""" def test_shutdown(self): """Send to pybitmessage SIGTERM and ensure it stopped""" - self.process.send_signal(signal.SIGTERM) - try: - # longer wait time because it's not a benchmark - self.process.wait(10) - except psutil.TimeoutExpired: - self.fail( - '%s has not stopped in 10 sec' % ' '.join(self._process_cmd)) + # longer wait time because it's not a benchmark + self.assertTrue( + self._stop_process(20), + '%s has not stopped in 20 sec' % ' '.join(self._process_cmd)) @classmethod def tearDownClass(cls):