def test_start__KeyboardInterrupt(self): worker = self.worker worker.blueprint = Mock(name='blueprint') worker.blueprint.start.side_effect = KeyboardInterrupt() worker.stop = Mock(name='stop') worker.start() worker.stop.assert_called_with(exitcode=EX_FAILURE)
def test_component_raises(self): worker = self.worker comp = Mock() worker.components = [comp] comp.start.side_effect = TypeError() worker.stop = Mock() worker.start() worker.stop.assert_called_with()
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)
def test_step_raises(self): worker = self.worker step = Mock() worker.steps = [step] step.start.side_effect = TypeError() worker.stop = Mock() worker.start() worker.stop.assert_called_with()
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()
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)
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_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()
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()
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()
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()