diff --git a/tangostationcontrol/tangostationcontrol/integration_test/toolkit/__init__.py b/tangostationcontrol/tangostationcontrol/integration_test/toolkit/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tangostationcontrol/tangostationcontrol/integration_test/toolkit/test_archiver.py b/tangostationcontrol/tangostationcontrol/integration_test/toolkit/test_archiver.py index ce3f1cac741098e7fa2beeb764a6cb863f8af9c6..a890ab0afd64f2cf350af37c9613246018e29c7e 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/toolkit/test_archiver.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/toolkit/test_archiver.py @@ -8,14 +8,22 @@ # See LICENSE.txt for more info. from tangostationcontrol.integration_test.base import BaseIntegrationTestCase -from tangostationcontrol.tangostationcontrol.toolkit.archiver import Archiver +from tangostationcontrol.toolkit.archiver import * +from tangostationcontrol.toolkit.retriever import RetrieverTimescale +from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy + +import time +from datetime import datetime class TestArchiver(BaseIntegrationTestCase): - - def test_archiver_initialisation(self): - """Test archiver main attributes""" + + def setUp(self): + super().setUp() self.archiver = Archiver() self.assertIsNotNone(self.archiver) + + def test_archiver_initialisation(self): + """Test archiver main attributes""" self.assertEqual(self.archiver.cm_name,"archiving/hdbppts/confmanager01") self.assertTrue(len(self.archiver.es_list)) # subscribers list not empty @@ -32,3 +40,82 @@ class TestArchiver(BaseIntegrationTestCase): """Test archiver configuration file""" config_dict = self.archiver.get_configuration() self.assertIsNotNone(config_dict) + # Apply the configuration file + self.archiver.apply_configuration(config_dict) + + def test_archive_scalar_attribute(self): + """Test if a scalar attribute is correctly archived""" + # Start RECV Device + recv_proxy = TestDeviceProxy("STAT/RECV/1") + recv_proxy.off() + time.sleep(1) + recv_proxy.initialise() + time.sleep(1) + self.assertEqual(DevState.STANDBY, recv_proxy.state()) + recv_proxy.set_defaults() + recv_proxy.on() + self.assertEqual(DevState.ON, recv_proxy.state()) + + # Safety operation that prevents event subscriber to go in Fault state + self.archiver.remove_attributes_in_error() + attr_fullname = 'stat/recv/1/recvtr_translator_busy_r' # boolean + self.archiver.add_attribute_to_archiver(attr_fullname, polling_period=1000, event_period=3000) + time.sleep(3) + # Test if the attribute has been correctly added to event subscriber + self.assertTrue(self.archiver.is_attribute_archived(attr_fullname)) + + # Retrieve data from DB views + self.retriever = RetrieverTimescale() + self.assertIsNotNone(self.retriever) + records = self.retriever.get_lofar_attribute(attr_fullname) + self.assertTrue(len(records)>0) + self.assertEqual('stat/recv/1',[item.device for item in records][-1]) # column device + self.assertEqual('recvtr_translator_busy_r',[item.name for item in records][-1]) # column attribute + self.assertEqual(datetime,type([item.data_time for item in records][-1])) # column datetime + self.assertEqual(bool,type([item.value for item in records][-1])) # column value + + # Remove attribute at the end of the test + self.archiver.remove_attribute_from_archiver(attr_fullname) + time.sleep(3) + # Test if the attribute has been correctly removed + self.assertFalse(self.archiver.is_attribute_archived(attr_fullname)) + recv_proxy.off() + + def test_archive_array_attribute(self): + """Test if an array attribute is correctly archived""" + # Start SDP Device + sdp_proxy = TestDeviceProxy("STAT/SDP/1") + sdp_proxy.off() + time.sleep(1) + sdp_proxy.initialise() + time.sleep(1) + self.assertEqual(DevState.STANDBY, sdp_proxy.state()) + sdp_proxy.set_defaults() + sdp_proxy.on() + self.assertEqual(DevState.ON, sdp_proxy.state()) + + # Safety operation that prevents event subscriber to go in Fault state + self.archiver.remove_attributes_in_error() + attr_fullname = 'stat/sdp/1/fpga_temp_r' # double + self.archiver.add_attribute_to_archiver(attr_fullname, polling_period=1000, event_period=3000) + time.sleep(5) + # Test if the attribute has been correctly added to event subscriber + self.assertTrue(self.archiver.is_attribute_archived(attr_fullname)) + + # Retrieve data from DB views + self.retriever = RetrieverTimescale() + self.assertIsNotNone(self.retriever) + records = self.retriever.get_lofar_attribute(attr_fullname) + self.assertTrue(len(records)>0) + self.assertEqual('stat/sdp/1',[item.device for item in records][-1]) # column device + self.assertEqual('fpga_temp_r',[item.name for item in records][-1]) # column attribute + self.assertEqual(datetime,type([item.data_time for item in records][-1])) # column datetime + self.assertEqual(int,type([item.x for item in records][-1])) # column index + self.assertEqual(float,type([item.value for item in records][-1])) # column value + + # Remove attribute at the end of the test + self.archiver.remove_attribute_from_archiver(attr_fullname) + time.sleep(3) + # Test if the attribute has been correctly removed + self.assertFalse(self.archiver.is_attribute_archived(attr_fullname)) + sdp_proxy.off()