From 51df0507e2db1f2b15ab06e6dd2dba3110b583fd Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 16 Apr 2018 10:00:23 +0300 Subject: [PATCH] Fixed signal files creation --- .travis.yml | 2 +- src/bitmessagemain.py | 7 ++++++- src/singleinstance.py | 2 +- src/tests/apinotify_handler.py | 10 +++------- src/tests/test_process.py | 17 ++++++++++++++--- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2acd619..1edba418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,5 @@ install: - python setup.py install script: - python checkdeps.py - - pybitmessage -t + - src/bitmessagemain.py -t - python setup.py test diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 20d48566..35236a04 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -185,7 +185,10 @@ class Main: elif opt in ("-c", "--curses"): state.curses = True elif opt in ("-t", "--test"): - state.testmode = daemon = True + state.testmode = True + if os.path.isfile(os.path.join( + state.appdata, 'unittest.lock')): + daemon = True state.enableGUI = False # run without a UI # Fallback: in case when no api command was issued state.last_api_response = time.time() @@ -363,6 +366,8 @@ class Main: if (state.testmode and time.time() - state.last_api_response >= 30): self.stop() + elif not state.enableGUI: + self.stop() def daemonize(self): grandfatherPid = os.getpid() diff --git a/src/singleinstance.py b/src/singleinstance.py index d28a8276..c2def912 100644 --- a/src/singleinstance.py +++ b/src/singleinstance.py @@ -28,7 +28,7 @@ class singleinstance: self.lockfile = os.path.normpath( os.path.join(state.appdata, 'singleton%s.lock' % flavor_id)) - if not self.daemon and not state.curses: + if state.enableGUI and not self.daemon and not state.curses: # Tells the already running (if any) application to get focus. import bitmessageqt bitmessageqt.init() diff --git a/src/tests/apinotify_handler.py b/src/tests/apinotify_handler.py index e39e01c5..f7674dad 100755 --- a/src/tests/apinotify_handler.py +++ b/src/tests/apinotify_handler.py @@ -1,14 +1,10 @@ #!/usr/bin/env python -import os import sys import tempfile -from datetime import datetime +from test_process import put_signal_file if __name__ == '__main__': - if sys.argv()[1] == 'startingUp': - with open( - os.path.join(tempfile.gettempdir(), '.api_started'), 'wb' - ) as start_file: - start_file.write(datetime.now()) + if sys.argv[1] == 'startingUp': + put_signal_file(tempfile.gettempdir(), '.api_started') diff --git a/src/tests/test_process.py b/src/tests/test_process.py index 0a2f200f..06fc2998 100644 --- a/src/tests/test_process.py +++ b/src/tests/test_process.py @@ -3,21 +3,30 @@ import subprocess import os import signal import tempfile -from time import sleep +import time import psutil +def put_signal_file(path, filename): + with open(os.path.join(path, filename), 'wb') as outfile: + outfile.write(str(time.time())) + + class TestProcessProto(unittest.TestCase): _process_cmd = ['pybitmessage', '-d'] _threads_count = 14 - _files = ('keys.dat', 'debug.log', 'messages.dat', 'knownnodes.dat') + _files = ( + 'keys.dat', 'debug.log', 'messages.dat', 'knownnodes.dat', + '.api_started', 'unittest.lock' + ) @classmethod def setUpClass(cls): cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir() + put_signal_file(cls.home, 'unittest.lock') subprocess.call(cls._process_cmd) - sleep(5) + time.sleep(5) cls.pid = int(cls._get_readline('singleton.lock')) cls.process = psutil.Process(cls.pid) @@ -78,6 +87,8 @@ class TestProcess(TestProcessProto): def test_files(self): """Check existence of PyBitmessage files""" for pfile in self._files: + if pfile.startswith('.'): + continue self.assertIsNot( self._get_readline(pfile), None, 'Failed to read file %s' % pfile