def testAlertsSetUpAndSendingViaBaseWorkerThread(self): # calls as they are made from child/client classes of BaseWorkerThread config = getConfig("/tmp") self.assertTrue(hasattr(config, "Alert")) # test the same way alerts are set up in the client code (currently # all cases via BaseWorkerThread) # this call creates .sender, but here will be set to None thread = BaseWorkerThread() thread.config = config thread.initAlerts(compName="test2") self.assertTrue(thread.sender) # set up a temporary alert message receiver handler, receiver = utils.setUpReceiver(config.Alert.address, config.Alert.controlAddr) # send an alert message msg = "this is my message 1" thread.sendAlert(10, msg=msg) # wait for the alert to arrive while len(handler.queue) == 0: time.sleep(0.3) print "%s waiting for alert to arrive ..." % inspect.stack()[0][3] self.assertEqual(len(handler.queue), 1) alert = handler.queue[0] self.assertEqual(alert["Component"], "test2") self.assertEqual(alert["Level"], 10) self.assertEqual(alert["Source"], thread.__class__.__name__) self.assertEqual(alert["Details"]["msg"], msg) thread.sender.unregister() receiver.shutdown()
def testAlertsSetUpAndSendingViaBaseWorkerThread(self): # calls as they are made from child/client classes of BaseWorkerThread config = getConfig("/tmp") self.assertTrue(hasattr(config, "Alert")) # test the same way alerts are set up in the client code (currently # all cases via BaseWorkerThread) # this call creates .sender, but here will be set to None thread = BaseWorkerThread() thread.config = config thread.initAlerts(compName = "test2") self.assertTrue(thread.sender) # set up a temporary alert message receiver handler, receiver = utils.setUpReceiver(config.Alert.address, config.Alert.controlAddr) # send an alert message msg = "this is my message 1" thread.sendAlert(10, msg = msg) # wait for the alert to arrive while len(handler.queue) == 0: time.sleep(0.3) print "%s waiting for alert to arrive ..." % inspect.stack()[0][3] self.assertEqual(len(handler.queue), 1) alert = handler.queue[0] self.assertEqual(alert["Component"], "test2") self.assertEqual(alert["Level"], 10) self.assertEqual(alert["Source"], thread.__class__.__name__) self.assertEqual(alert["Details"]["msg"], msg) thread.sender.unregister() receiver.shutdown()
def testAlertsMessagingNotSetUpViaBaseWorkerThread(self): # alerts will not be set up if 'config.Alert' etc is not provided config = Configuration() self.assertFalse(hasattr(config, "Alert")) # test the same way alerts are set up in the client code (currently # all cases via BaseWorkerThread) # this call creates .sender, but here will be set to None thread = BaseWorkerThread() thread.config = config thread.initAlerts(compName = "test1") self.assertFalse(thread.sender) # shall do nothing and not fail thread.sendAlert("nonsense", msg = "nonsense")
def testAlertsMessagingNotSetUpViaBaseWorkerThread(self): # alerts will not be set up if 'config.Alert' etc is not provided config = Configuration() self.assertFalse(hasattr(config, "Alert")) # test the same way alerts are set up in the client code (currently # all cases via BaseWorkerThread) # this call creates .sender, but here will be set to None thread = BaseWorkerThread() thread.config = config thread.initAlerts(compName="test1") self.assertFalse(thread.sender) # shall do nothing and not fail thread.sendAlert("nonsense", msg="nonsense")