Skip to content

Commit 2d9ea38

Browse files
committed
Add systemtest
1 parent e1a7d05 commit 2d9ea38

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dotenv import dotenv_values
33
import psycopg2
44
import pytest
5+
import stomp
56

67
# standard imports
78
import requests
@@ -76,3 +77,14 @@ def db_connection():
7677
time.sleep(1)
7778
yield conn
7879
conn.close()
80+
81+
82+
@pytest.fixture(scope="session")
83+
def amq_connection():
84+
"""activemq connection with config from env files"""
85+
config = dotenv_values(".env")
86+
assert config
87+
conn = stomp.Connection(host_and_ports=[("localhost", 61613)])
88+
conn.connect(config["ICAT_USER"], config["ICAT_PASS"], wait=True)
89+
yield conn
90+
conn.disconnect()

tests/test_SMS_messages.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""Test the status acquiring appears when a SMS message is received and before the data is ready"""
2+
3+
import time
4+
import json
5+
import tests.utils.db as db_utils
6+
7+
8+
class TestSMSQueues:
9+
instrument = "arcs"
10+
IPTS = "IPTS-11111"
11+
user = "InstrumentScientist"
12+
pwd = "InstrumentScientist"
13+
14+
def create_and_send_msg(self, conn, run_number):
15+
conn.send(
16+
f"/topic/SNS.{self.instrument.upper()}.APP.SMS",
17+
json.dumps(
18+
{
19+
"instrument": self.instrument,
20+
"facility": "SNS",
21+
"ipts": self.IPTS,
22+
"run_number": run_number,
23+
"data_file": "",
24+
"reason": "SMS run started",
25+
"msg_type": "0",
26+
}
27+
),
28+
)
29+
30+
def clear_run(self, conn, run_number):
31+
# remove everything for this run
32+
cursor = conn.cursor()
33+
cursor.execute("SELECT id FROM report_instrument where name = %s;", (self.instrument,))
34+
inst_id = cursor.fetchone()
35+
if inst_id is None:
36+
return
37+
38+
cursor.execute(
39+
"SELECT id FROM report_datarun WHERE instrument_id_id = %s AND run_number = %s;", (inst_id, run_number)
40+
)
41+
run_id = cursor.fetchone()
42+
if run_id is None:
43+
return
44+
45+
db_utils.clear_previous_runstatus(conn, run_id)
46+
cursor.execute("DELETE FROM report_workflowsummary WHERE run_id_id = %s;", run_id)
47+
cursor.execute("DELETE FROM report_instrumentstatus WHERE last_run_id_id = %s;", run_id)
48+
cursor.execute("DELETE FROM report_datarun WHERE id = %s;", (run_id))
49+
conn.commit()
50+
cursor.close()
51+
52+
def test_acquiring(self, amq_connection, db_connection, request_page):
53+
# remove data run so the tests always starts fresh
54+
self.clear_run(db_connection, 100)
55+
self.clear_run(db_connection, 101)
56+
# send SMS message for 2 runs
57+
self.create_and_send_msg(amq_connection, 100)
58+
self.create_and_send_msg(amq_connection, 101)
59+
60+
# wait a second while things run
61+
time.sleep(1)
62+
63+
# check IPTS page /report/arcs/experiment/IPTS-11111/ for acquiring
64+
response = request_page("/report/arcs/experiment/IPTS-11111/", self.user, self.pwd)
65+
assert response.status_code == 200
66+
assert response.text.count("acquiring") == 2
67+
68+
# now send data_ready for run 100 only and check that it is no longer acquiring
69+
self.create_and_send_msg(amq_connection, 100)
70+
71+
amq_connection.send(
72+
"/queue/POSTPROCESS.DATA_READY",
73+
json.dumps(
74+
{
75+
"instrument": self.instrument,
76+
"facility": "SNS",
77+
"ipts": self.IPTS,
78+
"run_number": 100,
79+
"data_file": "",
80+
}
81+
),
82+
)
83+
time.sleep(1)
84+
85+
# check IPTS page /report/arcs/experiment/IPTS-11111/ for acquiring
86+
response = request_page("/report/arcs/experiment/IPTS-11111/", self.user, self.pwd)
87+
assert response.status_code == 200
88+
assert response.text.count("acquiring") == 1 # 101 is still acquiring but not 100

0 commit comments

Comments
 (0)