Ejemplo n.º 1
0
 def test_in_process_delay(self):
     with watchdog.watch(self.logger, "in process", after=1.0):
         time.sleep(2)
     self.assertIn("DEBUG in process not completed after 1",
                   self.log.output)
     loglines = self.log.output.rstrip().split("\n")
     self.assertEqual(1, len(loglines), loglines)
Ejemplo n.º 2
0
 def test_in_process_delay(self):
     with watchdog.watch(self.logger, "in process", after=1.0):
         time.sleep(2)
     self.assertIn("DEBUG in process not completed after 1",
                   self.log.output)
     loglines = self.log.output.rstrip().split("\n")
     self.assertEqual(1, len(loglines), loglines)
Ejemplo n.º 3
0
 def test_level_setting(self):
     with watchdog.watch(self.logger, "in process",
                         level=logging.ERROR, after=1.0):
         time.sleep(2)
     self.assertIn("ERROR in process not completed after 1",
                   self.log.output)
     loglines = self.log.output.rstrip().split("\n")
     self.assertEqual(1, len(loglines), loglines)
Ejemplo n.º 4
0
 def test_in_process_exploding(self):
     try:
         with watchdog.watch(self.logger, "ungraceful exit", after=1.0):
             raise Exception()
     except Exception:
         pass
     # wait long enough to know there won't be a message emitted
     time.sleep(2)
     self.assertEqual('', self.log.output)
Ejemplo n.º 5
0
 def test_in_process_exploding(self):
     try:
         with watchdog.watch(self.logger, "ungraceful exit", after=1.0):
             raise Exception()
     except Exception:
         pass
     # wait long enough to know there won't be a message emitted
     time.sleep(2)
     self.assertEqual('', self.log.output)
Ejemplo n.º 6
0
 def test_level_setting(self):
     with watchdog.watch(self.logger,
                         "in process",
                         level=logging.ERROR,
                         after=1.0):
         time.sleep(2)
     self.assertIn("ERROR in process not completed after 1",
                   self.log.output)
     loglines = self.log.output.rstrip().split("\n")
     self.assertEqual(1, len(loglines), loglines)
Ejemplo n.º 7
0
import time
import logging

from oslo_concurrency import watchdog

LOG = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

def short_task():
    time.sleep(1)

def long_task():
    time.sleep(10)

if __name__ == '__main__':
    LOG.info("start")
    with watchdog.watch(LOG, "short task is over 5 sec",
                        level=logging.INFO,
                        after=5):
        short_task()

    with watchdog.watch(LOG, "long task is over 5 sec",
                        level=logging.INFO,
                        after=5):
        long_task()
    LOG.info("end")
Ejemplo n.º 8
0
from oslo_concurrency import watchdog
import subprocess
import logging

FORMAT = '%(asctime)-15s %(message)s'
logging.basicConfig(format=FORMAT)
LOG = logging.getLogger('mylogger')

with watchdog.watch(LOG, "subprocess call", logging.ERROR, after=2):
    subprocess.call("sleep 3", shell=True)
    print "done"
Ejemplo n.º 9
0
 def test_subprocess_delay(self):
     with watchdog.watch(self.logger, "subprocess", after=0.1):
         subprocess.call("sleep 2", shell=True)
     self.assertIn("DEBUG subprocess not completed after 0",
                   self.log.output)
Ejemplo n.º 10
0
 def test_in_process_delay_no_message(self):
     with watchdog.watch(self.logger, "in process", after=1.0):
         pass
     # wait long enough to know there won't be a message emitted
     time.sleep(2)
     self.assertEqual('', self.log.output)
Ejemplo n.º 11
0
 def test_subprocess_delay(self):
     with watchdog.watch(self.logger, "subprocess", after=0.1):
         subprocess.call("sleep 2", shell=True)
     self.assertIn("DEBUG subprocess not completed after 0",
                   self.log.output)
Ejemplo n.º 12
0
 def test_in_process_delay_no_message(self):
     with watchdog.watch(self.logger, "in process", after=1.0):
         pass
     # wait long enough to know there won't be a message emitted
     time.sleep(2)
     self.assertEqual('', self.log.output)