Esempio n. 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)
Esempio n. 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)
Esempio n. 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()
Esempio n. 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()
Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()