def wrapper(*args, **kw): m = Monitor() try: result = wrapper.original(*args, **kw) return result finally: m.stop()
def testMonitorStopAfterTimeout(self): from Products.LongRequestLogger.monitor import Monitor m = Monitor() s = Sleeper(m.dumper.timeout + 0.5) # sleep a little more than the timeout to be on the safe side s.sleep() m.stop() check_monitor_log(str(self.loghandler))
def testMonitorStopAfterTimeoutAndTwoIntervals(self): from Products.LongRequestLogger.monitor import Monitor m = Monitor() s = Sleeper(m.dumper.timeout + 2 * m.dumper.interval + 0.5) # sleep a little more than timeout + intervals to be on the safe # side s.sleep() m.stop() check_monitor_2_intervals_log(str(self.loghandler))
def testMonitorWithEnvironmentConfiguration(self): from Products.LongRequestLogger.monitor import Monitor os.environ['longrequestlogger_timeout'] = '3.5' os.environ['longrequestlogger_interval'] = '2' m = Monitor() s = Sleeper(m.dumper.timeout + m.dumper.interval + 0.5) # sleep a little more than the timeout to be on the safe side s.sleep() m.stop() check_monitor_environment_log(str(self.loghandler))
def testMonitorStopBeforeTimeout(self): from Products.LongRequestLogger.monitor import Monitor m = Monitor() # sleep just a little to let the other thread start s = Sleeper(0.01) s.sleep() self.assertTrue(m.isAlive()) m.stop() self.assertFalse(m.isAlive()) # unless this test is so slow that there were 2 seconds interval # between starting the monitor and stopping it, there should be no # logged messages self.assertFalse(self.loghandler.records)
def testMonitorConfigurationDisabled(self): from Products.LongRequestLogger.monitor import Monitor from Products.LongRequestLogger.dumper import DEFAULT_TIMEOUT from Products.LongRequestLogger.dumper import DEFAULT_INTERVAL os.environ['longrequestlogger_file'] = '' m = Monitor() s = Sleeper(DEFAULT_TIMEOUT + 2 * DEFAULT_INTERVAL + 0.5) # sleep a little more than timeout + intervals s.sleep() # the thread shouldn't run disabled self.assertFalse(m.isAlive()) # stopping shouldn't break nonetheless m.stop() self.assertFalse(m.isAlive()) # and there should be no records self.assertFalse(self.loghandler.records)