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.
This commit is contained in:
Dmitri Bogomolov 2019-03-13 17:56:26 +02:00
parent 4b72a433c6
commit 7b9824afc9
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 47 additions and 12 deletions

View File

@ -2,9 +2,11 @@
Various tests for config Various tests for config
""" """
import os
import unittest import unittest
from pybitmessage.bmconfigparser import BMConfigParser from pybitmessage.bmconfigparser import BMConfigParser
from test_process import TestProcessProto
class TestConfig(unittest.TestCase): class TestConfig(unittest.TestCase):
@ -34,3 +36,30 @@ class TestConfig(unittest.TestCase):
BMConfigParser().safeGetInt('nonexistent', 'nonexistent'), 0) BMConfigParser().safeGetInt('nonexistent', 'nonexistent'), 0)
self.assertEqual( self.assertEqual(
BMConfigParser().safeGetInt('nonexistent', 'nonexistent', 42), 42) 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)

View File

@ -47,6 +47,15 @@ class TestProcessProto(unittest.TestCase):
except (OSError, IOError): except (OSError, IOError):
pass 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 @classmethod
def _cleanup_files(cls): def _cleanup_files(cls):
for pfile in cls._files: for pfile in cls._files:
@ -58,12 +67,12 @@ class TestProcessProto(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
"""Ensures that pybitmessage stopped and removes files""" """Ensures that pybitmessage stopped and removes files"""
cls.process.send_signal(signal.SIGTERM)
try: try:
cls.process.wait(5) if not cls._stop_process():
except psutil.TimeoutExpired: print(open(os.path.join(cls.home, 'debug.log'), 'rb').read())
print(open(os.path.join(cls.home, 'debug.log'), 'rb').read()) cls.process.kill()
cls.process.kill() except psutil.NoSuchProcess:
pass
finally: finally:
cls._cleanup_files() cls._cleanup_files()
@ -93,13 +102,10 @@ class TestProcessShutdown(TestProcessProto):
"""Separate test case for SIGTERM""" """Separate test case for SIGTERM"""
def test_shutdown(self): def test_shutdown(self):
"""Send to pybitmessage SIGTERM and ensure it stopped""" """Send to pybitmessage SIGTERM and ensure it stopped"""
self.process.send_signal(signal.SIGTERM) # longer wait time because it's not a benchmark
try: self.assertTrue(
# longer wait time because it's not a benchmark self._stop_process(20),
self.process.wait(10) '%s has not stopped in 20 sec' % ' '.join(self._process_cmd))
except psutil.TimeoutExpired:
self.fail(
'%s has not stopped in 10 sec' % ' '.join(self._process_cmd))
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):