Fixed signal files creation

This commit is contained in:
Dmitri Bogomolov 2018-04-16 10:00:23 +03:00
parent 589900f7c3
commit 51df0507e2
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
5 changed files with 25 additions and 13 deletions

View File

@ -12,5 +12,5 @@ install:
- python setup.py install - python setup.py install
script: script:
- python checkdeps.py - python checkdeps.py
- pybitmessage -t - src/bitmessagemain.py -t
- python setup.py test - python setup.py test

View File

@ -185,7 +185,10 @@ class Main:
elif opt in ("-c", "--curses"): elif opt in ("-c", "--curses"):
state.curses = True state.curses = True
elif opt in ("-t", "--test"): 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 state.enableGUI = False # run without a UI
# Fallback: in case when no api command was issued # Fallback: in case when no api command was issued
state.last_api_response = time.time() state.last_api_response = time.time()
@ -363,6 +366,8 @@ class Main:
if (state.testmode and if (state.testmode and
time.time() - state.last_api_response >= 30): time.time() - state.last_api_response >= 30):
self.stop() self.stop()
elif not state.enableGUI:
self.stop()
def daemonize(self): def daemonize(self):
grandfatherPid = os.getpid() grandfatherPid = os.getpid()

View File

@ -28,7 +28,7 @@ class singleinstance:
self.lockfile = os.path.normpath( self.lockfile = os.path.normpath(
os.path.join(state.appdata, 'singleton%s.lock' % flavor_id)) 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. # Tells the already running (if any) application to get focus.
import bitmessageqt import bitmessageqt
bitmessageqt.init() bitmessageqt.init()

View File

@ -1,14 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
import os
import sys import sys
import tempfile import tempfile
from datetime import datetime from test_process import put_signal_file
if __name__ == '__main__': if __name__ == '__main__':
if sys.argv()[1] == 'startingUp': if sys.argv[1] == 'startingUp':
with open( put_signal_file(tempfile.gettempdir(), '.api_started')
os.path.join(tempfile.gettempdir(), '.api_started'), 'wb'
) as start_file:
start_file.write(datetime.now())

View File

@ -3,21 +3,30 @@ import subprocess
import os import os
import signal import signal
import tempfile import tempfile
from time import sleep import time
import psutil 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): class TestProcessProto(unittest.TestCase):
_process_cmd = ['pybitmessage', '-d'] _process_cmd = ['pybitmessage', '-d']
_threads_count = 14 _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 @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir() cls.home = os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
put_signal_file(cls.home, 'unittest.lock')
subprocess.call(cls._process_cmd) subprocess.call(cls._process_cmd)
sleep(5) time.sleep(5)
cls.pid = int(cls._get_readline('singleton.lock')) cls.pid = int(cls._get_readline('singleton.lock'))
cls.process = psutil.Process(cls.pid) cls.process = psutil.Process(cls.pid)
@ -78,6 +87,8 @@ class TestProcess(TestProcessProto):
def test_files(self): def test_files(self):
"""Check existence of PyBitmessage files""" """Check existence of PyBitmessage files"""
for pfile in self._files: for pfile in self._files:
if pfile.startswith('.'):
continue
self.assertIsNot( self.assertIsNot(
self._get_readline(pfile), None, self._get_readline(pfile), None,
'Failed to read file %s' % pfile 'Failed to read file %s' % pfile