def test_start__terminate(self): worker = self.worker worker.blueprint.shutdown_complete.set() worker.blueprint.started = 5 worker.blueprint.state = RUN worker.steps = [MockStep() for _ in range(5)] worker.start() for w in worker.steps[:3]: self.assertTrue(w.start.call_count) self.assertTrue(worker.blueprint.started, len(worker.steps)) self.assertEqual(worker.blueprint.state, RUN) worker.terminate() for step in worker.steps: self.assertTrue(step.terminate.call_count)
def test_start__terminate(self): worker = self.worker worker.namespace.shutdown_complete.set() worker.namespace.started = 5 worker.namespace.state = RUN worker.components = [Mock(), Mock(), Mock(), Mock(), Mock()] worker.start() for w in worker.components[:3]: self.assertTrue(w.start.call_count) self.assertTrue(worker.namespace.started, len(worker.components)) self.assertEqual(worker.namespace.state, RUN) worker.terminate() for component in worker.components: self.assertTrue(component.terminate.call_count)
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
def test_start__terminate(self): worker = self.worker worker._shutdown_complete.set() worker.components = [Mock(), Mock(), Mock(), Mock(), Mock()] for component in worker.components[:3]: component.terminate = None worker.start() for w in worker.components[:3]: self.assertTrue(w.start.call_count) self.assertTrue(worker._running, len(worker.components)) self.assertEqual(worker._state, RUN) worker.terminate() for component in worker.components[:3]: self.assertTrue(component.stop.call_count) self.assertTrue(worker.components[4].terminate.call_count)
def test_start__terminate(self): worker = self.worker worker.blueprint.shutdown_complete.set() worker.blueprint.started = 5 worker.blueprint.state = RUN worker.steps = [MockStep() for _ in range(5)] worker.start() for w in worker.steps[:3]: w.start.assert_called() assert worker.blueprint.started == len(worker.steps) assert worker.blueprint.state == RUN worker.terminate() for step in worker.steps: step.terminate.assert_called() worker.blueprint.state = TERMINATE worker.terminate()