Пример #1
0
 def test_use_pidfile(self, create_pidlock):
     create_pidlock.return_value = Mock()
     worker = self.create_worker(pidfile="pidfilelockfilepid")
     worker.components = []
     worker.start()
     self.assertTrue(create_pidlock.called)
     worker.stop()
     self.assertTrue(worker.pidlock.release.called)
Пример #2
0
 def test_use_pidfile(self, create_pidlock):
     create_pidlock.return_value = Mock()
     worker = self.create_worker(pidfile='pidfilelockfilepid')
     worker.components = []
     worker.start()
     self.assertTrue(create_pidlock.called)
     worker.stop()
     self.assertTrue(worker.pidlock.release.called)
Пример #3
0
 def test_use_pidfile(self, create_pidlock):
     create_pidlock.return_value = Mock()
     worker = self.create_worker(pidfile='pidfilelockfilepid')
     worker.steps = []
     worker.start()
     create_pidlock.assert_called()
     worker.stop()
     worker.pidlock.release.assert_called()
Пример #4
0
 def test_use_pidfile(self, create_pidlock):
     create_pidlock.return_value = Mock()
     worker = self.create_worker(pidfile='pidfilelockfilepid')
     worker.steps = []
     worker.start()
     create_pidlock.assert_called()
     worker.stop()
     worker.pidlock.release.assert_called()
Пример #5
0
    def test_start__stop(self):
        worker = self.worker
        worker._shutdown_complete.set()
        worker.components = [Mock(), Mock(), Mock(), Mock()]

        worker.start()
        for w in worker.components:
            self.assertTrue(w.start.call_count)
        worker.stop()
        for component in worker.components:
            self.assertTrue(w.stop.call_count)
Пример #6
0
    def test_start__stop(self):
        worker = self.worker
        worker._shutdown_complete.set()
        worker.components = [Mock(), Mock(), Mock(), Mock()]

        worker.start()
        for w in worker.components:
            self.assertTrue(w.start.call_count)
        worker.stop()
        for component in worker.components:
            self.assertTrue(w.stop.call_count)
Пример #7
0
    def test_dont_stop_or_terminate(self):
        worker = WorkController(concurrency=1, loglevel=0)
        worker.stop()
        self.assertNotEqual(worker._state, worker.CLOSE)
        worker.terminate()
        self.assertNotEqual(worker._state, worker.CLOSE)

        sigsafe, worker.pool.signal_safe = worker.pool.signal_safe, False
        try:
            worker._state = worker.RUN
            worker.stop(in_sighandler=True)
            self.assertNotEqual(worker._state, worker.CLOSE)
            worker.terminate(in_sighandler=True)
            self.assertNotEqual(worker._state, worker.CLOSE)
        finally:
            worker.pool.signal_safe = sigsafe
Пример #8
0
    def test_dont_stop_or_terminate(self):
        worker = WorkController(concurrency=1, loglevel=0)
        worker.stop()
        self.assertNotEqual(worker._state, worker.CLOSE)
        worker.terminate()
        self.assertNotEqual(worker._state, worker.CLOSE)

        sigsafe, worker.pool.signal_safe = worker.pool.signal_safe, False
        try:
            worker._state = worker.RUN
            worker.stop(in_sighandler=True)
            self.assertNotEqual(worker._state, worker.CLOSE)
            worker.terminate(in_sighandler=True)
            self.assertNotEqual(worker._state, worker.CLOSE)
        finally:
            worker.pool.signal_safe = sigsafe
Пример #9
0
    def test_start__stop(self):
        worker = self.worker
        worker.blueprint.shutdown_complete.set()
        worker.steps = [MockStep(StartStopStep(self)) for _ in range(4)]
        worker.blueprint.state = RUN
        worker.blueprint.started = 4
        for w in worker.steps:
            w.start = Mock()
            w.close = Mock()
            w.stop = Mock()

        worker.start()
        for w in worker.steps:
            self.assertTrue(w.start.call_count)
        worker.consumer = Mock()
        worker.stop()
        for stopstep in worker.steps:
            self.assertTrue(stopstep.close.call_count)
            self.assertTrue(stopstep.stop.call_count)

        # Doesn't close pool if no pool.
        worker.start()
        worker.pool = None
        worker.stop()

        # test that stop of None is not attempted
        worker.steps[-1] = None
        worker.start()
        worker.stop()
Пример #10
0
    def test_start__stop(self):
        worker = self.worker
        worker.blueprint.shutdown_complete.set()
        worker.steps = [MockStep(StartStopStep(self)) for _ in range(4)]
        worker.blueprint.state = RUN
        worker.blueprint.started = 4
        for w in worker.steps:
            w.start = Mock()
            w.close = Mock()
            w.stop = Mock()

        worker.start()
        for w in worker.steps:
            self.assertTrue(w.start.call_count)
        worker.consumer = Mock()
        worker.stop()
        for stopstep in worker.steps:
            self.assertTrue(stopstep.close.call_count)
            self.assertTrue(stopstep.stop.call_count)

        # Doesn't close pool if no pool.
        worker.start()
        worker.pool = None
        worker.stop()

        # test that stop of None is not attempted
        worker.steps[-1] = None
        worker.start()
        worker.stop()
Пример #11
0
    def test_start__stop(self):
        worker = self.worker
        worker.namespace.shutdown_complete.set()
        worker.components = [StartStopComponent(self) for _ in range(4)]
        worker.namespace.state = RUN
        worker.namespace.started = 4
        for w in worker.components:
            w.start = Mock()
            w.stop = Mock()

        worker.start()
        for w in worker.components:
            self.assertTrue(w.start.call_count)
        worker.stop()
        for w in worker.components:
            self.assertTrue(w.stop.call_count)

        # Doesn't close pool if no pool.
        worker.start()
        worker.pool = None
        worker.stop()

        # test that stop of None is not attempted
        worker.components[-1] = None
        worker.start()
        worker.stop()
Пример #12
0
    def test_start__stop(self):
        worker = self.worker
        worker.namespace.shutdown_complete.set()
        worker.components = [StartStopComponent(self) for _ in range(4)]
        worker.namespace.state = RUN
        worker.namespace.started = 4
        for w in worker.components:
            w.start = Mock()
            w.stop = Mock()

        worker.start()
        for w in worker.components:
            self.assertTrue(w.start.call_count)
        worker.stop()
        for w in worker.components:
            self.assertTrue(w.stop.call_count)

        # Doesn't close pool if no pool.
        worker.start()
        worker.pool = None
        worker.stop()

        # test that stop of None is not attempted
        worker.components[-1] = None
        worker.start()
        worker.stop()
Пример #13
0
    def test_start__stop(self):
        worker = self.worker
        worker._shutdown_complete.set()
        worker.components = [Mock(), Mock(), Mock(), Mock()]

        worker.start()
        for w in worker.components:
            self.assertTrue(w.start.call_count)
        worker.stop()
        for component in worker.components:
            self.assertTrue(w.stop.call_count)

        # Doesn't close pool if no pool.
        worker.start()
        worker.pool = None
        worker.stop()

        # test that stop of None is not attempted
        worker.components[-1] = None
        worker.start()
        worker.stop()
Пример #14
0
    def test_start__stop(self):
        worker = self.worker
        worker._shutdown_complete.set()
        worker.components = [Mock(), Mock(), Mock(), Mock()]

        worker.start()
        for w in worker.components:
            self.assertTrue(w.start.call_count)
        worker.stop()
        for component in worker.components:
            self.assertTrue(w.stop.call_count)

        # Doesn't close pool if no pool.
        worker.start()
        worker.pool = None
        worker.stop()

        # test that stop of None is not attempted
        worker.components[-1] = None
        worker.start()
        worker.stop()