def test_list_archived_only(self): controller.subscribe('test:long1', SubscriptionMode.Monitor(delta=0.01)).wait() controller.subscribe('test:long2', SubscriptionMode.Monitor(delta=0.123)).wait() controller.subscribe('test:long3', SubscriptionMode.Scan(period=123.1) ).wait() time.sleep(5) controller.unsubscribe('test:long1').wait() controller.unsubscribe('test:long2').wait() # still subscribed to test:long3 archived = dict(controller.list_archived(False)) #don't include currently subscribed self.assertItemsEqual(archived.keys(), ['test:long1', 'test:long2'])
def test_list_subscribed_only(self): controller.subscribe('DEFAULT.PV', SubscriptionMode.Monitor(delta=0.01)).wait() controller.subscribe('FOO.PV', SubscriptionMode.Monitor(delta=0.123)).wait() controller.subscribe('BAR.PV', SubscriptionMode.Scan(period=123.1) ).wait() subscribed = dict(controller.list_subscribed()) self.assertItemsEqual(subscribed.keys(), ['BAR.PV', 'DEFAULT.PV', 'FOO.PV']) controller.unsubscribe('FOO.PV').wait() subscribed = dict(controller.list_subscribed()) self.assertItemsEqual(subscribed.keys(), ['BAR.PV', 'DEFAULT.PV']) # yet 'FOO.PV' is still present in the archive arched = dict(controller.list_archived(False)) self.assertItemsEqual(arched.keys(), ['FOO.PV'])
def test_unsubscribe_scan(self): controller.subscribe(self.long_pvs[0], SubscriptionMode.Scan(period=1)) #check that the system has registered the subscription apv = controller.get_apv(self.long_pvs[0]) self.assertEqual( apv.name, self.long_pvs[0] ) # wait for a while so that we gather some data time.sleep(3) # request unsubscription unsub_req = controller.unsubscribe(self.long_pvs[0]) self.assertTrue(unsub_req) unsub_req.wait() before = controller.get_values(self.long_pvs[0]) # verify that the system has removed the pv apv = controller.get_apv(self.long_pvs[0]) self.assertFalse(apv.subscribed) # wait to see if we are still receiving data time.sleep(3) after = controller.get_values(self.long_pvs[0]) # we shouldn't have received any data during the last sleep period self.assertEqual(len(before), len(after)) # and the scan task's timer should have been cleaned up self.assertEqual(controller.timers.num_active_tasks, 0)
def test_unsubscribe_monitor(self): pvname = self.long_pvs[0] controller.subscribe(pvname, SubscriptionMode.Monitor(delta=0.01)) #check that the system has registered the subscription apv = controller.get_apv(pvname) self.assertEqual( apv.name, self.long_pvs[0] ) # wait for a while so that we gather some data time.sleep(2) # request unsubscription unsub_req = controller.unsubscribe(self.long_pvs[0]) self.assertTrue(unsub_req) unsub_req.wait() # take note of the data present before = controller.get_values(self.long_pvs[0])['rows'] # verify that the system has removed the pv apv = controller.get_apv(self.long_pvs[0]) self.assertFalse(apv.subscribed) # wait to see if we are still receiving data time.sleep(2) after = controller.get_values(self.long_pvs[0])['rows'] # we shouldn't have received any data during the last sleep period self.assertEqual(len(before), len(after))
def put(self, pvname): # modify if exists, ie, unsubscribe and resubscribe apv = controller.get_apv(pvname) if apv and apv.subscribed: controller.unsubscribe(pvname) # at this point, subscribe no matter what: if we were # already subscribed, we've just unsubscribed. body_json = self.request.body body = json.loads(body_json) # body should of the form # {mode: ...} mode = SubscriptionMode.parse(body["mode"]) try: future = controller.subscribe(pvname, mode) result = future.get(TIMEOUT) if result: self.win({"pvname": pvname, "mode": mode}) else: self.fail("Couldn't subscribe", {"pvname": pvname, "mode": mode}) except Exception as e: logger.exception(e) self.fail(str(e))
def delete(self, pvname): response = {"pvname": pvname} try: future = controller.unsubscribe(pvname) if future: res = future.get(TIMEOUT) if res: self.win(response) else: self.fail(res, code=408, response=response) else: # no future self.fail("Unknown PV '%s'" % pvname, code=404) except Exception as e: logger.exception(e) self.fail(str(e))
def test_unsubscribe_misc(self): # unsubscribe from an unknown pv self.assertIsNone(controller.unsubscribe('foobar'))