Пример #1
0
 def get(self, pvname):
     limit = self.get_argument("limit", 10)
     statuses = controller.get_statuses(pvname, limit)
     if statuses:
         self.win(statuses)
     else:
         self.fail(msg="Unknown PV '%s'" % pvname, code=404)
Пример #2
0
    def test_get_values_disconnected(self):
        conn_ts = datastore._get_timestamp_ms()
        futures = [ controller.subscribe(pv, SubscriptionMode.Monitor(delta=0.01)) \
                     for pv in self.existing_pvs ]
        results = [ fut.get() for fut in futures ]
        time.sleep(2)
        # when a pv gets disconnected, NaN should be stored as its value. 
        # moreover, the pv's status should reflect the disconnection at that
        # point in time
        for pv in self.existing_pvs:
            statuses = controller.get_statuses(pv)
            self.assertTrue(statuses)
            status = statuses[0]
            self.assertTrue(status['connected'])

            last_values = controller.get_values(pv)
            self.assertTrue(last_values['rows'])
            last_value = last_values['rows'][0]
            self.assertGreater(last_value['archived_at_ts'], conn_ts)
            self.assertGreater(last_value['value'], 1)


        predisconn_ts = datastore._get_timestamp_ms()
        _block_ioc(True)
        time.sleep(35)
        postdisconn_ts = datastore._get_timestamp_ms()

        for pv in self.existing_pvs:
            statuses = controller.get_statuses(pv)
            self.assertTrue(statuses)
            status = statuses[0]
            self.assertFalse(status['connected'])

            last_values = controller.get_values(pv)
            self.assertTrue(last_values['rows'])
            last_value = last_values['rows'][0]
            self.assertGreater(last_value['archived_at_ts'], predisconn_ts)
            self.assertGreater(postdisconn_ts, last_value['archived_at_ts'])
            self.assertIsNone(last_value['value'])

        _block_ioc(False)
Пример #3
0
    def test_get_statuses(self):
        # connect
        futures = [controller.subscribe(pv, SubscriptionMode.Monitor(delta=0.01)) for pv in self.pvs]
        [ fut.wait() for fut in futures ]
        
        conn_ts = datastore._get_timestamp_ms()
        # 1st status from initial connection => true
        #
        self.assertEqual(_block_ioc(True), 0)
        time.sleep(40)
        # 2nd status after disconnection from timeout => false
        #
        self.assertEqual(_block_ioc(False), 0)
        # 3rd status after unblocking IOC, reconnection => true
        time.sleep(2)


        for pv in self.existing_pvs: 
            statuses = controller.get_statuses(pv, limit=3)
            self.assertTrue(statuses)
            self.assertTrue(len(statuses), 3)

            [reconn, disconn, conn] = statuses

            self.assertTrue(conn['connected'])
            self.assertLess( (conn['timestamp'] - conn_ts)/1e6, 0.5 )

            self.assertFalse(disconn['connected'])
            self.assertTrue(reconn['connected'])

            self.assertEqual(reconn['pvname'], pv)
            self.assertEqual(conn['pvname'], pv)
            self.assertEqual(disconn['pvname'], pv)
            
        for fakepv in self.fake_pvs:
            statuses = controller.get_statuses(fakepv)
            # they must be there, with 'connected' set to false
            for status in statuses:
                self.assertFalse(status['connected'])
Пример #4
0
 def get(self):
     limit = self.get_argument("limit", 1)
     pvnames = [pvname for pvname, _ in controller.list_subscribed()]
     statuses = [controller.get_statuses(pvname, limit) for pvname in pvnames]
     self.win(statuses)