Esempio n. 1
0
    def testC_DashboardReporterPollerAlertSending_algorithm(self):
        """
        Cause exception (alert-worthy situation) in the algorithm()
        method.
        
        """
        myThread = threading.currentThread()
        config = self.getConfig()
        
        handler, self.alertsReceiver = \
            utils.setUpReceiver(config.Alert.address, config.Alert.controlAddr)

        # emulate exception behaviour
        def raiseException():
            raise Exception("My test exception.")
            
        dashboardReporter = DashboardReporterPoller(config = config)
        dashboardReporter.pollCouch = raiseException
        self.assertRaises(Exception, dashboardReporter.algorithm)
        # wait for the generated alert to arrive
        while len(handler.queue) == 0:
            time.sleep(0.3)
            print "%s waiting for alert to arrive ..." % inspect.stack()[0][3]
            
        self.alertsReceiver.shutdown()
        self.alertsReceiver = None
        # now check if the alert was properly sent
        self.assertEqual(len(handler.queue), 1)
        alert = handler.queue[0]
        self.assertEqual(alert["Source"], dashboardReporter.__class__.__name__)
        self.assertEqual(alert["Component"], "DashboardReporter")
        return