Esempio n. 1
0
 def test_child(self):
     logger = FakeLogger()
     service.fork = lambda *a: 0
     service.sustain_workers(1, self.worker_func, logger)
     # Asserts the TERM and HUP signal handlers are cleared with the child.
     self.assertEquals(
         set(self.signal_calls[-2:]),
         set([(service.SIGHUP, 0), (service.SIGTERM, 0)]))
     self.assertEquals(self.worker_func_calls, [(0,)])
     self.assertEquals(logger.debug_calls, [
         ('wid:000 ppid:%s pid:%s Starting worker.' %
             (service.getppid(), service.getpid()),),
         ('wid:000 ppid:%s pid:%s Worker exited.' %
             (service.getppid(), service.getpid()),)])
     self.assertEquals(logger.info_calls, [])
Esempio n. 2
0
 def test_workers0(self):
     logger = FakeLogger()
     service.sustain_workers(0, self.worker_func, logger)
     self.assertEquals(self.worker_func_calls, [(0,)])
     self.assertEquals(
         logger.debug_calls,
         [('wid:000 pid:%s Starting inproc worker.' % service.getpid(),)])
     self.assertEquals(
         logger.info_calls,
         [('Exiting due to workers = 0 mode.',)])
Esempio n. 3
0
    def test_child_exception(self):

        def _worker_func(*args):
            raise Exception('testing')

        logger = FakeLogger()
        service.fork = lambda *a: 0
        exc = None
        try:
            service.sustain_workers(1, _worker_func, logger)
        except Exception as err:
            exc = err
        self.assertEqual(str(exc), 'testing')
        self.assertEqual(logger.debug_calls, [
            ('wid:000 ppid:%s pid:%s Starting worker.' %
                (service.getppid(), service.getpid()),)])
        self.assertEqual(logger.info_calls, [])
        self.assertEqual(logger.exception_calls, [(
            'wid:000 ppid:%s pid:%s Worker exited due to exception: testing' %
            (service.getppid(), service.getpid()),)])
Esempio n. 4
0
    def test_child_exception(self):

        def _worker_func(*args):
            raise Exception('testing')

        logger = FakeLogger()
        service.fork = lambda *a: 0
        exc = None
        try:
            service.sustain_workers(1, _worker_func, logger)
        except Exception, err:
            exc = err
        self.assertEquals(str(exc), 'testing')
        self.assertEquals(logger.debug_calls, [
            ('wid:000 ppid:%s pid:%s Starting worker.' %
                (service.getppid(), service.getpid()),)])
        self.assertEquals(logger.info_calls, [])
        self.assertEquals(logger.exception_calls, [
            ('wid:000 ppid:%s pid:%s Worker exited due to exception: testing' %
                (service.getppid(), service.getpid()),)])

    def test_no_sleep_on_initial_launch(self):
        fork_calls = []

        def _os_wait(*args):
            raise KeyboardInterrupt()

        def _fork(*args):
            fork_calls.append(args)
            return len(fork_calls)