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
script:
- python checkdeps.py
- pybitmessage -t
- src/bitmessagemain.py -t
- python setup.py test

View File

@ -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()

View File

@ -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()

View File

@ -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')

View File

@ -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