diff --git a/src/api.py b/src/api.py index d01ba4fb..d7b1d344 100755 --- a/src/api.py +++ b/src/api.py @@ -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) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index f5f9fa09..45f2484d 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -46,7 +46,8 @@ 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 from pybitmessage import depends @@ -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 diff --git a/src/helper_test.py b/src/helper_test.py new file mode 100644 index 00000000..b8041564 --- /dev/null +++ b/src/helper_test.py @@ -0,0 +1,10 @@ +""" +src/helper_test.py +================================= +""" +import collections + +""" +Core Dummy testcase instance +""" +TestCoreDummy = collections.namedtuple('TestCoreDummy',['errors','failures']) \ No newline at end of file diff --git a/src/network/threads.py b/src/network/threads.py index a338a916..62eac214 100755 --- a/src/network/threads.py +++ b/src/network/threads.py @@ -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() diff --git a/src/shutdown.py b/src/shutdown.py index 58ddf287..af04fae1 100755 --- a/src/shutdown.py +++ b/src/shutdown.py @@ -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) diff --git a/src/tests/test_api.py b/src/tests/test_api.py index 62805069..b31523b9 100755 --- a/src/tests/test_api.py +++ b/src/tests/test_api.py @@ -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): diff --git a/src/tests/test_process.py b/src/tests/test_process.py index 222d9c7f..1faff471 100755 --- a/src/tests/test_process.py +++ b/src/tests/test_process.py @@ -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