Changes into test mode:
run in background, stop after 30 sec since last API response
This commit is contained in:
parent
8aafb71024
commit
5b1d2e56a1
|
@ -7,7 +7,10 @@ addons:
|
||||||
- build-essential
|
- build-essential
|
||||||
- libcap-dev
|
- libcap-dev
|
||||||
install:
|
install:
|
||||||
|
- pip install -r requirements.txt
|
||||||
|
- ln -s src pybitmessage # tests environment
|
||||||
- python setup.py install
|
- python setup.py install
|
||||||
script:
|
script:
|
||||||
- python checkdeps.py
|
- python checkdeps.py
|
||||||
- pybitmessage -t
|
- pybitmessage -t
|
||||||
|
- python setup.py test
|
||||||
|
|
|
@ -1456,7 +1456,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
def _handle_request(self, method, params):
|
def _handle_request(self, method, params):
|
||||||
if method not in self.handlers:
|
if method not in self.handlers:
|
||||||
raise APIError(20, 'Invalid method: %s' % method)
|
raise APIError(20, 'Invalid method: %s' % method)
|
||||||
return self.handlers[method](self, params)
|
result = self.handlers[method](self, params)
|
||||||
|
state.last_api_response = time.time()
|
||||||
|
return result
|
||||||
|
|
||||||
def _dispatch(self, method, params):
|
def _dispatch(self, method, params):
|
||||||
# pylint: disable=attribute-defined-outside-init
|
# pylint: disable=attribute-defined-outside-init
|
||||||
|
|
|
@ -25,10 +25,8 @@ import getopt
|
||||||
# Used to capture a Ctrl-C keypress so that Bitmessage can shutdown gracefully.
|
# Used to capture a Ctrl-C keypress so that Bitmessage can shutdown gracefully.
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
from datetime import datetime
|
import time
|
||||||
from struct import pack
|
from struct import pack
|
||||||
from subprocess import call
|
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
from helper_startup import (
|
from helper_startup import (
|
||||||
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections
|
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections
|
||||||
|
@ -189,6 +187,20 @@ class Main:
|
||||||
elif opt in ("-t", "--test"):
|
elif opt in ("-t", "--test"):
|
||||||
state.testmode = daemon = True
|
state.testmode = 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
|
||||||
|
state.last_api_response = time.time()
|
||||||
|
# Apply special settings
|
||||||
|
config = BMConfigParser()
|
||||||
|
config.set(
|
||||||
|
'bitmessagesettings', 'apienabled', 'true')
|
||||||
|
config.set(
|
||||||
|
'bitmessagesettings', 'apiusername', 'username')
|
||||||
|
config.set(
|
||||||
|
'bitmessagesettings', 'apipassword', 'password')
|
||||||
|
config.set(
|
||||||
|
'bitmessagesettings', 'apinotifypath',
|
||||||
|
os.path.join(app_dir, 'tests', 'apinotify_handler.py')
|
||||||
|
)
|
||||||
|
|
||||||
# is the application already running? If yes then exit.
|
# is the application already running? If yes then exit.
|
||||||
if state.enableGUI and not state.curses and not depends.check_pyqt():
|
if state.enableGUI and not state.curses and not depends.check_pyqt():
|
||||||
|
@ -206,7 +218,7 @@ class Main:
|
||||||
)
|
)
|
||||||
shared.thisapp = singleinstance("", daemon)
|
shared.thisapp = singleinstance("", daemon)
|
||||||
|
|
||||||
if daemon and not state.testmode:
|
if daemon:
|
||||||
with shared.printLock:
|
with shared.printLock:
|
||||||
print('Running as a daemon. Send TERM signal to end.')
|
print('Running as a daemon. Send TERM signal to end.')
|
||||||
self.daemonize()
|
self.daemonize()
|
||||||
|
@ -346,12 +358,11 @@ class Main:
|
||||||
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
|
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
|
||||||
|
|
||||||
if daemon:
|
if daemon:
|
||||||
if state.testmode:
|
|
||||||
sleep(30)
|
|
||||||
# make testing
|
|
||||||
self.stop()
|
|
||||||
while state.shutdown == 0:
|
while state.shutdown == 0:
|
||||||
sleep(1)
|
time.sleep(1)
|
||||||
|
if (state.testmode and
|
||||||
|
time.time() - state.last_api_response >= 30):
|
||||||
|
self.stop()
|
||||||
|
|
||||||
def daemonize(self):
|
def daemonize(self):
|
||||||
grandfatherPid = os.getpid()
|
grandfatherPid = os.getpid()
|
||||||
|
@ -362,7 +373,7 @@ class Main:
|
||||||
shared.thisapp.cleanup()
|
shared.thisapp.cleanup()
|
||||||
# wait until grandchild ready
|
# wait until grandchild ready
|
||||||
while True:
|
while True:
|
||||||
sleep(1)
|
time.sleep(1)
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# fork not implemented
|
# fork not implemented
|
||||||
|
@ -383,7 +394,7 @@ class Main:
|
||||||
shared.thisapp.cleanup()
|
shared.thisapp.cleanup()
|
||||||
# wait until child ready
|
# wait until child ready
|
||||||
while True:
|
while True:
|
||||||
sleep(1)
|
time.sleep(1)
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# fork not implemented
|
# fork not implemented
|
||||||
|
|
Reference in New Issue
Block a user