Solved the pybitmessage -t issue and added new file for the dummy objects for the test core

This commit is contained in:
jai.s 2020-09-25 17:58:54 +05:30
parent f409b15535
commit e1df39065c
No known key found for this signature in database
GPG Key ID: 360CFA25EFC67D12
7 changed files with 35 additions and 41 deletions

View File

@ -94,9 +94,7 @@ class StoppableXMLRPCServer(SimpleXMLRPCServer):
"""Start the SimpleXMLRPCServer"""
# pylint: disable=arguments-differ
while state.shutdown == 0:
logger.error('before handle_request')
self.handle_request()
logger.error('After handle_request')
# This thread, of which there is only one, runs the API.
@ -108,20 +106,14 @@ class singleAPI(StoppableThread):
def stopThread(self):
super(singleAPI, self).stopThread()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
logger.error('11111111111 stopThread 11111111 ')
try:
logger.error('11111111111 stopThread 113 ')
s.connect((
BMConfigParser().get('bitmessagesettings', 'apiinterface'),
BMConfigParser().getint('bitmessagesettings', 'apiport')
))
logger.error('11111111111 stopThread 118 ')
s.shutdown(socket.SHUT_RDWR)
logger.error('11111111111 stopThread 120 ')
s.close()
logger.error('11111111111 stopThread 122 ')
except BaseException:
logger.error('11111111111 stopThread except BaseException')
pass
def run(self):
@ -1497,6 +1489,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
def _dispatch(self, method, params):
# pylint: disable=attribute-defined-outside-init
self.cookies = []
validuser = self.APIAuthenticateClient()
if not validuser:
time.sleep(2)

View File

@ -46,6 +46,7 @@ try:
# Synchronous threads
from threads import (set_thread_name, printLock,
addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
from helper_test import TestCoreDummy
except ModuleNotFoundError:
from pybitmessage import defaults
@ -73,6 +74,7 @@ except ModuleNotFoundError:
from pybitmessage.threads import (set_thread_name, printLock,
addressGenerator, objectProcessor, singleCleaner,
singleWorker, sqlThread)
from pybitmessage.helper_test import TestCoreDummy
app_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(app_dir)
@ -393,7 +395,6 @@ class Main(object):
# bitmessageqt.run()
else:
config.remove_option('bitmessagesettings', 'dontconnect')
if daemon:
while state.shutdown == 0:
time.sleep(1)
@ -405,19 +406,24 @@ class Main(object):
else:
state.enableGUI = True
# pylint: disable=relative-import
test_core_result = TestCoreDummy(errors = 1,failures = 1)
try:
from tests import core as test_core
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:
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
def daemonize():
@ -449,10 +455,6 @@ class Main(object):
# unlock
state.thisapp.cleanup()
# wait until child ready
# while True:
# print('---------------489-------------------')
# time.sleep(1)
os._exit(0) # pylint: disable=protected-access
except AttributeError:
pass

10
src/helper_test.py Normal file
View File

@ -0,0 +1,10 @@
"""
src/helper_test.py
=================================
"""
import collections
"""
Core Dummy testcase instance
"""
TestCoreDummy = collections.namedtuple('TestCoreDummy',['errors','failures'])

View File

@ -22,8 +22,6 @@ class StoppableThread(threading.Thread):
def stopThread(self):
"""Stop the thread"""
if self.name == 'singleAPI':
logger.error('yes inside the the stopthread')
self._stopped = True
self.stop.set()

View File

@ -37,22 +37,18 @@ def doCleanShutdown():
for thread in threading.enumerate():
# if thread.name == 'singleAPI':
if thread.isAlive() and isinstance(thread, StoppableThread):
# logger.error('printing the stop thread -{}'.format(
# thread))
thread.stopThread()
logger.error('thread name -{} thread._is_stopped {}'.format(
thread.name, thread._is_stopped))
UISignalQueue.put((
'updateStatusBar',
'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()
logger.error('Done saving knownNodes list of peers to disk')
logger.info('Done saving knownNodes list of peers to disk')
UISignalQueue.put((
'updateStatusBar',
'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((
'updateStatusBar',
'Flushing inventory in memory out to disk.'
@ -76,14 +72,14 @@ def doCleanShutdown():
and isinstance(thread, StoppableThread)
and thread.name != 'SQL'
):
logger.error("Waiting for thread %s", thread.name)
logger.debug("Waiting for thread %s", thread.name)
thread.join()
# This one last useless query will guarantee that the previous flush
# committed and that the
# objectProcessorThread committed before we close the program.
sqlQuery('SELECT address FROM subscriptions')
logger.error('Finished flushing inventory.')
logger.info('Finished flushing inventory.')
sqlStoredProcedure('exit')
# flush queues
@ -99,10 +95,10 @@ def doCleanShutdown():
try:
if shared.thisapp.daemon or not state.enableGUI: # ..fixme:: redundant?
logger.error('Clean shutdown complete.')
logger.info('Clean shutdown complete.')
shared.thisapp.cleanup()
os._exit(0) # pylint: disable=protected-access
except AttributeError:
logger.error('Core shutdown complete.')
logger.info('Core shutdown complete.')
for thread in threading.enumerate():
logger.error('Thread %s still running', thread.name)
logger.debug('Thread %s still running', thread.name)

View File

@ -14,10 +14,6 @@ from pybitmessage.debug import logger
class TestAPIProto(TestProcessProto):
"""Test case logic for testing API"""
_process_cmd = ['pybitmessage', '-t']
# _files = (
# 'keys.dat', 'messages.dat', 'knownnodes.dat',
# '.api_started', 'unittest.lock'
# )
@classmethod
def setUpClass(cls):

View File

@ -37,7 +37,6 @@ class TestProcessProto(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""Setup environment and start pybitmessage"""
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
put_signal_file(cls.home, 'unittest.lock')
subprocess.call(cls._process_cmd) # nosec