Skip to content
Snippets Groups Projects
Commit 3ba8cede authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-828: use temporary file to store state in

parent e5ecbbf4
No related branches found
No related tags found
2 merge requests!74Lofar release 4 0,!72Resolve SW-828
......@@ -32,6 +32,8 @@ from lofar.messaging.messagebus import *
from lofar.sas.otdb.TreeStatusEvents import create_service
import threading
import sys
from datetime import datetime, timedelta
from tempfile import NamedTemporaryFile
import logging
logger = logging.getLogger(__name__)
......@@ -44,17 +46,22 @@ with OTDBTestInstance('t_TreeStatusEvents.in.unittest_db.dump.gz') as test_db:
with tmp_exchange.create_temporary_queue() as tmp_queue:
with tmp_queue.create_frombus() as frombus:
t = threading.Thread(target=create_service, args=(tmp_exchange.address, test_db.dbcreds, '/dev/null'))
t.daemon = True
t.start()
with NamedTemporaryFile(mode='w+') as state_file:
state_file.file.write((datetime.utcnow()-timedelta(seconds=2)).strftime("%Y-%m-%d %H:%M:%S"))
state_file.file.flush()
test_db.db.executeQuery("select setTreeState(1, %d, %d::INT2,'%s'::boolean);" % (1099266, 500, False))
test_db.db.commit()
t = threading.Thread(target=create_service, args=(tmp_exchange.address, test_db.dbcreds, state_file.name))
t.daemon = True
t.start()
msg = frombus.receive(timeout=500, acknowledge=True) # TreeStateEvent are send every 2 seconds
logger.info(msg)
try:
ok = (msg.content['treeID'] == 1099266 and msg.content['state'] == 'queued')
except IndexError:
ok = False
sys.exit(not ok) # 0 = success
test_db.db.executeQuery("select setTreeState(1, %d, %d::INT2,'%s'::boolean);" % (1099266, 500, False))
test_db.db.commit()
msg = frombus.receive(timeout=500, acknowledge=True) # TreeStateEvent are send every 2 seconds
logger.info(msg)
try:
ok = (msg.content['treeID'] == 1099266 and msg.content['state'] == 'queued')
except IndexError:
ok = False
sys.exit(not ok) # 0 = success
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment