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:
parent
4b72a433c6
commit
7b9824afc9
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
Reference in New Issue
Block a user