Solved the pybitmessage -t issue and added new file for the dummy objects for the test core
This commit is contained in:
parent
f409b15535
commit
e1df39065c
|
@ -94,9 +94,7 @@ class StoppableXMLRPCServer(SimpleXMLRPCServer):
|
||||||
"""Start the SimpleXMLRPCServer"""
|
"""Start the SimpleXMLRPCServer"""
|
||||||
# pylint: disable=arguments-differ
|
# pylint: disable=arguments-differ
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
logger.error('before handle_request')
|
|
||||||
self.handle_request()
|
self.handle_request()
|
||||||
logger.error('After handle_request')
|
|
||||||
|
|
||||||
|
|
||||||
# This thread, of which there is only one, runs the API.
|
# This thread, of which there is only one, runs the API.
|
||||||
|
@ -108,20 +106,14 @@ class singleAPI(StoppableThread):
|
||||||
def stopThread(self):
|
def stopThread(self):
|
||||||
super(singleAPI, self).stopThread()
|
super(singleAPI, self).stopThread()
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
logger.error('11111111111 stopThread 11111111 ')
|
|
||||||
try:
|
try:
|
||||||
logger.error('11111111111 stopThread 113 ')
|
|
||||||
s.connect((
|
s.connect((
|
||||||
BMConfigParser().get('bitmessagesettings', 'apiinterface'),
|
BMConfigParser().get('bitmessagesettings', 'apiinterface'),
|
||||||
BMConfigParser().getint('bitmessagesettings', 'apiport')
|
BMConfigParser().getint('bitmessagesettings', 'apiport')
|
||||||
))
|
))
|
||||||
logger.error('11111111111 stopThread 118 ')
|
|
||||||
s.shutdown(socket.SHUT_RDWR)
|
s.shutdown(socket.SHUT_RDWR)
|
||||||
logger.error('11111111111 stopThread 120 ')
|
|
||||||
s.close()
|
s.close()
|
||||||
logger.error('11111111111 stopThread 122 ')
|
|
||||||
except BaseException:
|
except BaseException:
|
||||||
logger.error('11111111111 stopThread except BaseException')
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -1497,6 +1489,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
|
|
||||||
def _dispatch(self, method, params):
|
def _dispatch(self, method, params):
|
||||||
# pylint: disable=attribute-defined-outside-init
|
# pylint: disable=attribute-defined-outside-init
|
||||||
|
self.cookies = []
|
||||||
validuser = self.APIAuthenticateClient()
|
validuser = self.APIAuthenticateClient()
|
||||||
if not validuser:
|
if not validuser:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
|
@ -46,7 +46,8 @@ try:
|
||||||
# Synchronous threads
|
# Synchronous threads
|
||||||
from threads import (set_thread_name, printLock,
|
from threads import (set_thread_name, printLock,
|
||||||
addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
|
addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
|
||||||
|
from helper_test import TestCoreDummy
|
||||||
|
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
from pybitmessage import defaults
|
from pybitmessage import defaults
|
||||||
from pybitmessage import depends
|
from pybitmessage import depends
|
||||||
|
@ -73,6 +74,7 @@ except ModuleNotFoundError:
|
||||||
from pybitmessage.threads import (set_thread_name, printLock,
|
from pybitmessage.threads import (set_thread_name, printLock,
|
||||||
addressGenerator, objectProcessor, singleCleaner,
|
addressGenerator, objectProcessor, singleCleaner,
|
||||||
singleWorker, sqlThread)
|
singleWorker, sqlThread)
|
||||||
|
from pybitmessage.helper_test import TestCoreDummy
|
||||||
|
|
||||||
app_dir = os.path.dirname(os.path.abspath(__file__))
|
app_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
os.chdir(app_dir)
|
os.chdir(app_dir)
|
||||||
|
@ -393,7 +395,6 @@ class Main(object):
|
||||||
# bitmessageqt.run()
|
# bitmessageqt.run()
|
||||||
else:
|
else:
|
||||||
config.remove_option('bitmessagesettings', 'dontconnect')
|
config.remove_option('bitmessagesettings', 'dontconnect')
|
||||||
|
|
||||||
if daemon:
|
if daemon:
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -405,19 +406,24 @@ class Main(object):
|
||||||
else:
|
else:
|
||||||
state.enableGUI = True
|
state.enableGUI = True
|
||||||
# pylint: disable=relative-import
|
# pylint: disable=relative-import
|
||||||
|
test_core_result = TestCoreDummy(errors = 1,failures = 1)
|
||||||
try:
|
try:
|
||||||
from tests import core as test_core
|
from tests import core as test_core
|
||||||
test_core_result = test_core.run()
|
test_core_result = test_core.run()
|
||||||
state.enableGUI = True
|
|
||||||
self.stop()
|
|
||||||
test_core.cleanup()
|
|
||||||
sys.exit(
|
|
||||||
'Core tests failed!'
|
|
||||||
if test_core_result.errors or test_core_result.failures
|
|
||||||
else 0
|
|
||||||
)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
finally:
|
||||||
|
state.enableGUI = True
|
||||||
|
self.stop()
|
||||||
|
try:
|
||||||
|
test_core.cleanup()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
sys.exit(
|
||||||
|
'Core tests failed!'
|
||||||
|
if test_core_result.errors or test_core_result.failures
|
||||||
|
else 0
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def daemonize():
|
def daemonize():
|
||||||
|
@ -449,10 +455,6 @@ class Main(object):
|
||||||
# unlock
|
# unlock
|
||||||
state.thisapp.cleanup()
|
state.thisapp.cleanup()
|
||||||
# wait until child ready
|
# wait until child ready
|
||||||
|
|
||||||
# while True:
|
|
||||||
# print('---------------489-------------------')
|
|
||||||
# time.sleep(1)
|
|
||||||
os._exit(0) # pylint: disable=protected-access
|
os._exit(0) # pylint: disable=protected-access
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
10
src/helper_test.py
Normal file
10
src/helper_test.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
"""
|
||||||
|
src/helper_test.py
|
||||||
|
=================================
|
||||||
|
"""
|
||||||
|
import collections
|
||||||
|
|
||||||
|
"""
|
||||||
|
Core Dummy testcase instance
|
||||||
|
"""
|
||||||
|
TestCoreDummy = collections.namedtuple('TestCoreDummy',['errors','failures'])
|
|
@ -22,8 +22,6 @@ class StoppableThread(threading.Thread):
|
||||||
|
|
||||||
def stopThread(self):
|
def stopThread(self):
|
||||||
"""Stop the thread"""
|
"""Stop the thread"""
|
||||||
if self.name == 'singleAPI':
|
|
||||||
logger.error('yes inside the the stopthread')
|
|
||||||
self._stopped = True
|
self._stopped = True
|
||||||
self.stop.set()
|
self.stop.set()
|
||||||
|
|
||||||
|
|
|
@ -37,22 +37,18 @@ def doCleanShutdown():
|
||||||
for thread in threading.enumerate():
|
for thread in threading.enumerate():
|
||||||
# if thread.name == 'singleAPI':
|
# if thread.name == 'singleAPI':
|
||||||
if thread.isAlive() and isinstance(thread, StoppableThread):
|
if thread.isAlive() and isinstance(thread, StoppableThread):
|
||||||
# logger.error('printing the stop thread -{}'.format(
|
|
||||||
# thread))
|
|
||||||
thread.stopThread()
|
thread.stopThread()
|
||||||
logger.error('thread name -{} thread._is_stopped {}'.format(
|
|
||||||
thread.name, thread._is_stopped))
|
|
||||||
|
|
||||||
UISignalQueue.put((
|
UISignalQueue.put((
|
||||||
'updateStatusBar',
|
'updateStatusBar',
|
||||||
'Saving the knownNodes list of peers to disk...'))
|
'Saving the knownNodes list of peers to disk...'))
|
||||||
logger.error('Saving knownNodes list of peers to disk')
|
logger.info('Saving knownNodes list of peers to disk')
|
||||||
saveKnownNodes()
|
saveKnownNodes()
|
||||||
logger.error('Done saving knownNodes list of peers to disk')
|
logger.info('Done saving knownNodes list of peers to disk')
|
||||||
UISignalQueue.put((
|
UISignalQueue.put((
|
||||||
'updateStatusBar',
|
'updateStatusBar',
|
||||||
'Done saving the knownNodes list of peers to disk.'))
|
'Done saving the knownNodes list of peers to disk.'))
|
||||||
logger.error('Flushing inventory in memory out to disk...')
|
logger.info('Flushing inventory in memory out to disk...')
|
||||||
UISignalQueue.put((
|
UISignalQueue.put((
|
||||||
'updateStatusBar',
|
'updateStatusBar',
|
||||||
'Flushing inventory in memory out to disk.'
|
'Flushing inventory in memory out to disk.'
|
||||||
|
@ -76,14 +72,14 @@ def doCleanShutdown():
|
||||||
and isinstance(thread, StoppableThread)
|
and isinstance(thread, StoppableThread)
|
||||||
and thread.name != 'SQL'
|
and thread.name != 'SQL'
|
||||||
):
|
):
|
||||||
logger.error("Waiting for thread %s", thread.name)
|
logger.debug("Waiting for thread %s", thread.name)
|
||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
# This one last useless query will guarantee that the previous flush
|
# This one last useless query will guarantee that the previous flush
|
||||||
# committed and that the
|
# committed and that the
|
||||||
# objectProcessorThread committed before we close the program.
|
# objectProcessorThread committed before we close the program.
|
||||||
sqlQuery('SELECT address FROM subscriptions')
|
sqlQuery('SELECT address FROM subscriptions')
|
||||||
logger.error('Finished flushing inventory.')
|
logger.info('Finished flushing inventory.')
|
||||||
sqlStoredProcedure('exit')
|
sqlStoredProcedure('exit')
|
||||||
|
|
||||||
# flush queues
|
# flush queues
|
||||||
|
@ -99,10 +95,10 @@ def doCleanShutdown():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if shared.thisapp.daemon or not state.enableGUI: # ..fixme:: redundant?
|
if shared.thisapp.daemon or not state.enableGUI: # ..fixme:: redundant?
|
||||||
logger.error('Clean shutdown complete.')
|
logger.info('Clean shutdown complete.')
|
||||||
shared.thisapp.cleanup()
|
shared.thisapp.cleanup()
|
||||||
os._exit(0) # pylint: disable=protected-access
|
os._exit(0) # pylint: disable=protected-access
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logger.error('Core shutdown complete.')
|
logger.info('Core shutdown complete.')
|
||||||
for thread in threading.enumerate():
|
for thread in threading.enumerate():
|
||||||
logger.error('Thread %s still running', thread.name)
|
logger.debug('Thread %s still running', thread.name)
|
||||||
|
|
|
@ -14,10 +14,6 @@ from pybitmessage.debug import logger
|
||||||
class TestAPIProto(TestProcessProto):
|
class TestAPIProto(TestProcessProto):
|
||||||
"""Test case logic for testing API"""
|
"""Test case logic for testing API"""
|
||||||
_process_cmd = ['pybitmessage', '-t']
|
_process_cmd = ['pybitmessage', '-t']
|
||||||
# _files = (
|
|
||||||
# 'keys.dat', 'messages.dat', 'knownnodes.dat',
|
|
||||||
# '.api_started', 'unittest.lock'
|
|
||||||
# )
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|
|
@ -37,7 +37,6 @@ class TestProcessProto(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
"""Setup environment and start pybitmessage"""
|
"""Setup environment and start pybitmessage"""
|
||||||
|
|
||||||
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
|
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
|
||||||
put_signal_file(cls.home, 'unittest.lock')
|
put_signal_file(cls.home, 'unittest.lock')
|
||||||
subprocess.call(cls._process_cmd) # nosec
|
subprocess.call(cls._process_cmd) # nosec
|
||||||
|
|
Reference in New Issue
Block a user